18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci//
38c2ecf20Sopenharmony_ci// mt6358.c  --  mt6358 ALSA SoC audio codec driver
48c2ecf20Sopenharmony_ci//
58c2ecf20Sopenharmony_ci// Copyright (c) 2018 MediaTek Inc.
68c2ecf20Sopenharmony_ci// Author: KaiChieh Chuang <kaichieh.chuang@mediatek.com>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
98c2ecf20Sopenharmony_ci#include <linux/module.h>
108c2ecf20Sopenharmony_ci#include <linux/of_device.h>
118c2ecf20Sopenharmony_ci#include <linux/delay.h>
128c2ecf20Sopenharmony_ci#include <linux/kthread.h>
138c2ecf20Sopenharmony_ci#include <linux/sched.h>
148c2ecf20Sopenharmony_ci#include <linux/mfd/mt6397/core.h>
158c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <sound/soc.h>
188c2ecf20Sopenharmony_ci#include <sound/tlv.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include "mt6358.h"
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cienum {
238c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_HSOUTL,
248c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_HSOUTR,
258c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_HPOUTL,
268c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_HPOUTR,
278c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_LINEOUTL,
288c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_LINEOUTR,
298c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_MICAMP1,
308c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_MICAMP2,
318c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_TYPE_MAX
328c2ecf20Sopenharmony_ci};
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cienum {
358c2ecf20Sopenharmony_ci	MUX_ADC_L,
368c2ecf20Sopenharmony_ci	MUX_ADC_R,
378c2ecf20Sopenharmony_ci	MUX_PGA_L,
388c2ecf20Sopenharmony_ci	MUX_PGA_R,
398c2ecf20Sopenharmony_ci	MUX_MIC_TYPE,
408c2ecf20Sopenharmony_ci	MUX_HP_L,
418c2ecf20Sopenharmony_ci	MUX_HP_R,
428c2ecf20Sopenharmony_ci	MUX_NUM,
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cienum {
468c2ecf20Sopenharmony_ci	DEVICE_HP,
478c2ecf20Sopenharmony_ci	DEVICE_LO,
488c2ecf20Sopenharmony_ci	DEVICE_RCV,
498c2ecf20Sopenharmony_ci	DEVICE_MIC1,
508c2ecf20Sopenharmony_ci	DEVICE_MIC2,
518c2ecf20Sopenharmony_ci	DEVICE_NUM
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* Supply widget subseq */
558c2ecf20Sopenharmony_cienum {
568c2ecf20Sopenharmony_ci	/* common */
578c2ecf20Sopenharmony_ci	SUPPLY_SEQ_CLK_BUF,
588c2ecf20Sopenharmony_ci	SUPPLY_SEQ_AUD_GLB,
598c2ecf20Sopenharmony_ci	SUPPLY_SEQ_CLKSQ,
608c2ecf20Sopenharmony_ci	SUPPLY_SEQ_VOW_AUD_LPW,
618c2ecf20Sopenharmony_ci	SUPPLY_SEQ_AUD_VOW,
628c2ecf20Sopenharmony_ci	SUPPLY_SEQ_VOW_CLK,
638c2ecf20Sopenharmony_ci	SUPPLY_SEQ_VOW_LDO,
648c2ecf20Sopenharmony_ci	SUPPLY_SEQ_TOP_CK,
658c2ecf20Sopenharmony_ci	SUPPLY_SEQ_TOP_CK_LAST,
668c2ecf20Sopenharmony_ci	SUPPLY_SEQ_AUD_TOP,
678c2ecf20Sopenharmony_ci	SUPPLY_SEQ_AUD_TOP_LAST,
688c2ecf20Sopenharmony_ci	SUPPLY_SEQ_AFE,
698c2ecf20Sopenharmony_ci	/* capture */
708c2ecf20Sopenharmony_ci	SUPPLY_SEQ_ADC_SUPPLY,
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cienum {
748c2ecf20Sopenharmony_ci	CH_L = 0,
758c2ecf20Sopenharmony_ci	CH_R,
768c2ecf20Sopenharmony_ci	NUM_CH,
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#define REG_STRIDE 2
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistruct mt6358_priv {
828c2ecf20Sopenharmony_ci	struct device *dev;
838c2ecf20Sopenharmony_ci	struct regmap *regmap;
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	unsigned int dl_rate;
868c2ecf20Sopenharmony_ci	unsigned int ul_rate;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	int ana_gain[AUDIO_ANALOG_VOLUME_TYPE_MAX];
898c2ecf20Sopenharmony_ci	unsigned int mux_select[MUX_NUM];
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	int dev_counter[DEVICE_NUM];
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	int mtkaif_protocol;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	struct regulator *avdd_reg;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	int wov_enabled;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	unsigned int dmic_one_wire_mode;
1008c2ecf20Sopenharmony_ci};
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ciint mt6358_set_mtkaif_protocol(struct snd_soc_component *cmpnt,
1038c2ecf20Sopenharmony_ci			       int mtkaif_protocol)
1048c2ecf20Sopenharmony_ci{
1058c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	priv->mtkaif_protocol = mtkaif_protocol;
1088c2ecf20Sopenharmony_ci	return 0;
1098c2ecf20Sopenharmony_ci}
1108c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt6358_set_mtkaif_protocol);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cistatic void playback_gpio_set(struct mt6358_priv *priv)
1138c2ecf20Sopenharmony_ci{
1148c2ecf20Sopenharmony_ci	/* set gpio mosi mode */
1158c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE2_CLR,
1168c2ecf20Sopenharmony_ci			   0x01f8, 0x01f8);
1178c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE2_SET,
1188c2ecf20Sopenharmony_ci			   0xffff, 0x0249);
1198c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE2,
1208c2ecf20Sopenharmony_ci			   0xffff, 0x0249);
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistatic void playback_gpio_reset(struct mt6358_priv *priv)
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci	/* set pad_aud_*_mosi to GPIO mode and dir input
1268c2ecf20Sopenharmony_ci	 * reason:
1278c2ecf20Sopenharmony_ci	 * pad_aud_dat_mosi*, because the pin is used as boot strap
1288c2ecf20Sopenharmony_ci	 * don't clean clk/sync, for mtkaif protocol 2
1298c2ecf20Sopenharmony_ci	 */
1308c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE2_CLR,
1318c2ecf20Sopenharmony_ci			   0x01f8, 0x01f8);
1328c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE2,
1338c2ecf20Sopenharmony_ci			   0x01f8, 0x0000);
1348c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_DIR0,
1358c2ecf20Sopenharmony_ci			   0xf << 8, 0x0);
1368c2ecf20Sopenharmony_ci}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistatic void capture_gpio_set(struct mt6358_priv *priv)
1398c2ecf20Sopenharmony_ci{
1408c2ecf20Sopenharmony_ci	/* set gpio miso mode */
1418c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE3_CLR,
1428c2ecf20Sopenharmony_ci			   0xffff, 0xffff);
1438c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE3_SET,
1448c2ecf20Sopenharmony_ci			   0xffff, 0x0249);
1458c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE3,
1468c2ecf20Sopenharmony_ci			   0xffff, 0x0249);
1478c2ecf20Sopenharmony_ci}
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_cistatic void capture_gpio_reset(struct mt6358_priv *priv)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci	/* set pad_aud_*_miso to GPIO mode and dir input
1528c2ecf20Sopenharmony_ci	 * reason:
1538c2ecf20Sopenharmony_ci	 * pad_aud_clk_miso, because when playback only the miso_clk
1548c2ecf20Sopenharmony_ci	 * will also have 26m, so will have power leak
1558c2ecf20Sopenharmony_ci	 * pad_aud_dat_miso*, because the pin is used as boot strap
1568c2ecf20Sopenharmony_ci	 */
1578c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE3_CLR,
1588c2ecf20Sopenharmony_ci			   0xffff, 0xffff);
1598c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE3,
1608c2ecf20Sopenharmony_ci			   0xffff, 0x0000);
1618c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_DIR0,
1628c2ecf20Sopenharmony_ci			   0xf << 12, 0x0);
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci/* use only when not govern by DAPM */
1668c2ecf20Sopenharmony_cistatic int mt6358_set_dcxo(struct mt6358_priv *priv, bool enable)
1678c2ecf20Sopenharmony_ci{
1688c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_DCXO_CW14,
1698c2ecf20Sopenharmony_ci			   0x1 << RG_XO_AUDIO_EN_M_SFT,
1708c2ecf20Sopenharmony_ci			   (enable ? 1 : 0) << RG_XO_AUDIO_EN_M_SFT);
1718c2ecf20Sopenharmony_ci	return 0;
1728c2ecf20Sopenharmony_ci}
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci/* use only when not govern by DAPM */
1758c2ecf20Sopenharmony_cistatic int mt6358_set_clksq(struct mt6358_priv *priv, bool enable)
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	/* audio clk source from internal dcxo */
1788c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON6,
1798c2ecf20Sopenharmony_ci			   RG_CLKSQ_IN_SEL_TEST_MASK_SFT,
1808c2ecf20Sopenharmony_ci			   0x0);
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	/* Enable/disable CLKSQ 26MHz */
1838c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON6,
1848c2ecf20Sopenharmony_ci			   RG_CLKSQ_EN_MASK_SFT,
1858c2ecf20Sopenharmony_ci			   (enable ? 1 : 0) << RG_CLKSQ_EN_SFT);
1868c2ecf20Sopenharmony_ci	return 0;
1878c2ecf20Sopenharmony_ci}
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci/* use only when not govern by DAPM */
1908c2ecf20Sopenharmony_cistatic int mt6358_set_aud_global_bias(struct mt6358_priv *priv, bool enable)
1918c2ecf20Sopenharmony_ci{
1928c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON13,
1938c2ecf20Sopenharmony_ci			   RG_AUDGLB_PWRDN_VA28_MASK_SFT,
1948c2ecf20Sopenharmony_ci			   (enable ? 0 : 1) << RG_AUDGLB_PWRDN_VA28_SFT);
1958c2ecf20Sopenharmony_ci	return 0;
1968c2ecf20Sopenharmony_ci}
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci/* use only when not govern by DAPM */
1998c2ecf20Sopenharmony_cistatic int mt6358_set_topck(struct mt6358_priv *priv, bool enable)
2008c2ecf20Sopenharmony_ci{
2018c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUD_TOP_CKPDN_CON0,
2028c2ecf20Sopenharmony_ci			   0x0066, enable ? 0x0 : 0x66);
2038c2ecf20Sopenharmony_ci	return 0;
2048c2ecf20Sopenharmony_ci}
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_cistatic int mt6358_mtkaif_tx_enable(struct mt6358_priv *priv)
2078c2ecf20Sopenharmony_ci{
2088c2ecf20Sopenharmony_ci	switch (priv->mtkaif_protocol) {
2098c2ecf20Sopenharmony_ci	case MT6358_MTKAIF_PROTOCOL_2_CLK_P2:
2108c2ecf20Sopenharmony_ci		/* MTKAIF TX format setting */
2118c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap,
2128c2ecf20Sopenharmony_ci				   MT6358_AFE_ADDA_MTKAIF_CFG0,
2138c2ecf20Sopenharmony_ci				   0xffff, 0x0010);
2148c2ecf20Sopenharmony_ci		/* enable aud_pad TX fifos */
2158c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap,
2168c2ecf20Sopenharmony_ci				   MT6358_AFE_AUD_PAD_TOP,
2178c2ecf20Sopenharmony_ci				   0xff00, 0x3800);
2188c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap,
2198c2ecf20Sopenharmony_ci				   MT6358_AFE_AUD_PAD_TOP,
2208c2ecf20Sopenharmony_ci				   0xff00, 0x3900);
2218c2ecf20Sopenharmony_ci		break;
2228c2ecf20Sopenharmony_ci	case MT6358_MTKAIF_PROTOCOL_2:
2238c2ecf20Sopenharmony_ci		/* MTKAIF TX format setting */
2248c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap,
2258c2ecf20Sopenharmony_ci				   MT6358_AFE_ADDA_MTKAIF_CFG0,
2268c2ecf20Sopenharmony_ci				   0xffff, 0x0010);
2278c2ecf20Sopenharmony_ci		/* enable aud_pad TX fifos */
2288c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap,
2298c2ecf20Sopenharmony_ci				   MT6358_AFE_AUD_PAD_TOP,
2308c2ecf20Sopenharmony_ci				   0xff00, 0x3100);
2318c2ecf20Sopenharmony_ci		break;
2328c2ecf20Sopenharmony_ci	case MT6358_MTKAIF_PROTOCOL_1:
2338c2ecf20Sopenharmony_ci	default:
2348c2ecf20Sopenharmony_ci		/* MTKAIF TX format setting */
2358c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap,
2368c2ecf20Sopenharmony_ci				   MT6358_AFE_ADDA_MTKAIF_CFG0,
2378c2ecf20Sopenharmony_ci				   0xffff, 0x0000);
2388c2ecf20Sopenharmony_ci		/* enable aud_pad TX fifos */
2398c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap,
2408c2ecf20Sopenharmony_ci				   MT6358_AFE_AUD_PAD_TOP,
2418c2ecf20Sopenharmony_ci				   0xff00, 0x3100);
2428c2ecf20Sopenharmony_ci		break;
2438c2ecf20Sopenharmony_ci	}
2448c2ecf20Sopenharmony_ci	return 0;
2458c2ecf20Sopenharmony_ci}
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_cistatic int mt6358_mtkaif_tx_disable(struct mt6358_priv *priv)
2488c2ecf20Sopenharmony_ci{
2498c2ecf20Sopenharmony_ci	/* disable aud_pad TX fifos */
2508c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_AUD_PAD_TOP,
2518c2ecf20Sopenharmony_ci			   0xff00, 0x3000);
2528c2ecf20Sopenharmony_ci	return 0;
2538c2ecf20Sopenharmony_ci}
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ciint mt6358_mtkaif_calibration_enable(struct snd_soc_component *cmpnt)
2568c2ecf20Sopenharmony_ci{
2578c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	playback_gpio_set(priv);
2608c2ecf20Sopenharmony_ci	capture_gpio_set(priv);
2618c2ecf20Sopenharmony_ci	mt6358_mtkaif_tx_enable(priv);
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	mt6358_set_dcxo(priv, true);
2648c2ecf20Sopenharmony_ci	mt6358_set_aud_global_bias(priv, true);
2658c2ecf20Sopenharmony_ci	mt6358_set_clksq(priv, true);
2668c2ecf20Sopenharmony_ci	mt6358_set_topck(priv, true);
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci	/* set dat_miso_loopback on */
2698c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDIO_DIG_CFG,
2708c2ecf20Sopenharmony_ci			   RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_MASK_SFT,
2718c2ecf20Sopenharmony_ci			   1 << RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_SFT);
2728c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDIO_DIG_CFG,
2738c2ecf20Sopenharmony_ci			   RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_MASK_SFT,
2748c2ecf20Sopenharmony_ci			   1 << RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_SFT);
2758c2ecf20Sopenharmony_ci	return 0;
2768c2ecf20Sopenharmony_ci}
2778c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt6358_mtkaif_calibration_enable);
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ciint mt6358_mtkaif_calibration_disable(struct snd_soc_component *cmpnt)
2808c2ecf20Sopenharmony_ci{
2818c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	/* set dat_miso_loopback off */
2848c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDIO_DIG_CFG,
2858c2ecf20Sopenharmony_ci			   RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_MASK_SFT,
2868c2ecf20Sopenharmony_ci			   0 << RG_AUD_PAD_TOP_DAT_MISO2_LOOPBACK_SFT);
2878c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDIO_DIG_CFG,
2888c2ecf20Sopenharmony_ci			   RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_MASK_SFT,
2898c2ecf20Sopenharmony_ci			   0 << RG_AUD_PAD_TOP_DAT_MISO_LOOPBACK_SFT);
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci	mt6358_set_topck(priv, false);
2928c2ecf20Sopenharmony_ci	mt6358_set_clksq(priv, false);
2938c2ecf20Sopenharmony_ci	mt6358_set_aud_global_bias(priv, false);
2948c2ecf20Sopenharmony_ci	mt6358_set_dcxo(priv, false);
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	mt6358_mtkaif_tx_disable(priv);
2978c2ecf20Sopenharmony_ci	playback_gpio_reset(priv);
2988c2ecf20Sopenharmony_ci	capture_gpio_reset(priv);
2998c2ecf20Sopenharmony_ci	return 0;
3008c2ecf20Sopenharmony_ci}
3018c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt6358_mtkaif_calibration_disable);
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ciint mt6358_set_mtkaif_calibration_phase(struct snd_soc_component *cmpnt,
3048c2ecf20Sopenharmony_ci					int phase_1, int phase_2)
3058c2ecf20Sopenharmony_ci{
3068c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDIO_DIG_CFG,
3098c2ecf20Sopenharmony_ci			   RG_AUD_PAD_TOP_PHASE_MODE_MASK_SFT,
3108c2ecf20Sopenharmony_ci			   phase_1 << RG_AUD_PAD_TOP_PHASE_MODE_SFT);
3118c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDIO_DIG_CFG,
3128c2ecf20Sopenharmony_ci			   RG_AUD_PAD_TOP_PHASE_MODE2_MASK_SFT,
3138c2ecf20Sopenharmony_ci			   phase_2 << RG_AUD_PAD_TOP_PHASE_MODE2_SFT);
3148c2ecf20Sopenharmony_ci	return 0;
3158c2ecf20Sopenharmony_ci}
3168c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt6358_set_mtkaif_calibration_phase);
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci/* dl pga gain */
3198c2ecf20Sopenharmony_cienum {
3208c2ecf20Sopenharmony_ci	DL_GAIN_8DB = 0,
3218c2ecf20Sopenharmony_ci	DL_GAIN_0DB = 8,
3228c2ecf20Sopenharmony_ci	DL_GAIN_N_1DB = 9,
3238c2ecf20Sopenharmony_ci	DL_GAIN_N_10DB = 18,
3248c2ecf20Sopenharmony_ci	DL_GAIN_N_40DB = 0x1f,
3258c2ecf20Sopenharmony_ci};
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci#define DL_GAIN_N_10DB_REG (DL_GAIN_N_10DB << 7 | DL_GAIN_N_10DB)
3288c2ecf20Sopenharmony_ci#define DL_GAIN_N_40DB_REG (DL_GAIN_N_40DB << 7 | DL_GAIN_N_40DB)
3298c2ecf20Sopenharmony_ci#define DL_GAIN_REG_MASK 0x0f9f
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_cistatic void hp_zcd_disable(struct mt6358_priv *priv)
3328c2ecf20Sopenharmony_ci{
3338c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_ZCD_CON0, 0x0000);
3348c2ecf20Sopenharmony_ci}
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_cistatic void hp_main_output_ramp(struct mt6358_priv *priv, bool up)
3378c2ecf20Sopenharmony_ci{
3388c2ecf20Sopenharmony_ci	int i = 0, stage = 0;
3398c2ecf20Sopenharmony_ci	int target = 7;
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	/* Enable/Reduce HPL/R main output stage step by step */
3428c2ecf20Sopenharmony_ci	for (i = 0; i <= target; i++) {
3438c2ecf20Sopenharmony_ci		stage = up ? i : target - i;
3448c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON1,
3458c2ecf20Sopenharmony_ci				   0x7 << 8, stage << 8);
3468c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON1,
3478c2ecf20Sopenharmony_ci				   0x7 << 11, stage << 11);
3488c2ecf20Sopenharmony_ci		usleep_range(100, 150);
3498c2ecf20Sopenharmony_ci	}
3508c2ecf20Sopenharmony_ci}
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_cistatic void hp_aux_feedback_loop_gain_ramp(struct mt6358_priv *priv, bool up)
3538c2ecf20Sopenharmony_ci{
3548c2ecf20Sopenharmony_ci	int i = 0, stage = 0;
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	/* Reduce HP aux feedback loop gain step by step */
3578c2ecf20Sopenharmony_ci	for (i = 0; i <= 0xf; i++) {
3588c2ecf20Sopenharmony_ci		stage = up ? i : 0xf - i;
3598c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON9,
3608c2ecf20Sopenharmony_ci				   0xf << 12, stage << 12);
3618c2ecf20Sopenharmony_ci		usleep_range(100, 150);
3628c2ecf20Sopenharmony_ci	}
3638c2ecf20Sopenharmony_ci}
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_cistatic void hp_pull_down(struct mt6358_priv *priv, bool enable)
3668c2ecf20Sopenharmony_ci{
3678c2ecf20Sopenharmony_ci	int i;
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	if (enable) {
3708c2ecf20Sopenharmony_ci		for (i = 0x0; i <= 0x6; i++) {
3718c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON4,
3728c2ecf20Sopenharmony_ci					   0x7, i);
3738c2ecf20Sopenharmony_ci			usleep_range(600, 700);
3748c2ecf20Sopenharmony_ci		}
3758c2ecf20Sopenharmony_ci	} else {
3768c2ecf20Sopenharmony_ci		for (i = 0x6; i >= 0x1; i--) {
3778c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON4,
3788c2ecf20Sopenharmony_ci					   0x7, i);
3798c2ecf20Sopenharmony_ci			usleep_range(600, 700);
3808c2ecf20Sopenharmony_ci		}
3818c2ecf20Sopenharmony_ci	}
3828c2ecf20Sopenharmony_ci}
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_cistatic bool is_valid_hp_pga_idx(int reg_idx)
3858c2ecf20Sopenharmony_ci{
3868c2ecf20Sopenharmony_ci	return (reg_idx >= DL_GAIN_8DB && reg_idx <= DL_GAIN_N_10DB) ||
3878c2ecf20Sopenharmony_ci	       reg_idx == DL_GAIN_N_40DB;
3888c2ecf20Sopenharmony_ci}
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_cistatic void headset_volume_ramp(struct mt6358_priv *priv, int from, int to)
3918c2ecf20Sopenharmony_ci{
3928c2ecf20Sopenharmony_ci	int offset = 0, count = 0, reg_idx;
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci	if (!is_valid_hp_pga_idx(from) || !is_valid_hp_pga_idx(to))
3958c2ecf20Sopenharmony_ci		dev_warn(priv->dev, "%s(), volume index is not valid, from %d, to %d\n",
3968c2ecf20Sopenharmony_ci			 __func__, from, to);
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci	dev_info(priv->dev, "%s(), from %d, to %d\n",
3998c2ecf20Sopenharmony_ci		 __func__, from, to);
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci	if (to > from)
4028c2ecf20Sopenharmony_ci		offset = to - from;
4038c2ecf20Sopenharmony_ci	else
4048c2ecf20Sopenharmony_ci		offset = from - to;
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci	while (offset >= 0) {
4078c2ecf20Sopenharmony_ci		if (to > from)
4088c2ecf20Sopenharmony_ci			reg_idx = from + count;
4098c2ecf20Sopenharmony_ci		else
4108c2ecf20Sopenharmony_ci			reg_idx = from - count;
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci		if (is_valid_hp_pga_idx(reg_idx)) {
4138c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap,
4148c2ecf20Sopenharmony_ci					   MT6358_ZCD_CON2,
4158c2ecf20Sopenharmony_ci					   DL_GAIN_REG_MASK,
4168c2ecf20Sopenharmony_ci					   (reg_idx << 7) | reg_idx);
4178c2ecf20Sopenharmony_ci			usleep_range(200, 300);
4188c2ecf20Sopenharmony_ci		}
4198c2ecf20Sopenharmony_ci		offset--;
4208c2ecf20Sopenharmony_ci		count++;
4218c2ecf20Sopenharmony_ci	}
4228c2ecf20Sopenharmony_ci}
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_cistatic int mt6358_put_volsw(struct snd_kcontrol *kcontrol,
4258c2ecf20Sopenharmony_ci			    struct snd_ctl_elem_value *ucontrol)
4268c2ecf20Sopenharmony_ci{
4278c2ecf20Sopenharmony_ci	struct snd_soc_component *component =
4288c2ecf20Sopenharmony_ci			snd_soc_kcontrol_component(kcontrol);
4298c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(component);
4308c2ecf20Sopenharmony_ci	struct soc_mixer_control *mc =
4318c2ecf20Sopenharmony_ci			(struct soc_mixer_control *)kcontrol->private_value;
4328c2ecf20Sopenharmony_ci	unsigned int reg;
4338c2ecf20Sopenharmony_ci	int ret;
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci	ret = snd_soc_put_volsw(kcontrol, ucontrol);
4368c2ecf20Sopenharmony_ci	if (ret < 0)
4378c2ecf20Sopenharmony_ci		return ret;
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci	switch (mc->reg) {
4408c2ecf20Sopenharmony_ci	case MT6358_ZCD_CON2:
4418c2ecf20Sopenharmony_ci		regmap_read(priv->regmap, MT6358_ZCD_CON2, &reg);
4428c2ecf20Sopenharmony_ci		priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] =
4438c2ecf20Sopenharmony_ci			(reg >> RG_AUDHPLGAIN_SFT) & RG_AUDHPLGAIN_MASK;
4448c2ecf20Sopenharmony_ci		priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] =
4458c2ecf20Sopenharmony_ci			(reg >> RG_AUDHPRGAIN_SFT) & RG_AUDHPRGAIN_MASK;
4468c2ecf20Sopenharmony_ci		break;
4478c2ecf20Sopenharmony_ci	case MT6358_ZCD_CON1:
4488c2ecf20Sopenharmony_ci		regmap_read(priv->regmap, MT6358_ZCD_CON1, &reg);
4498c2ecf20Sopenharmony_ci		priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTL] =
4508c2ecf20Sopenharmony_ci			(reg >> RG_AUDLOLGAIN_SFT) & RG_AUDLOLGAIN_MASK;
4518c2ecf20Sopenharmony_ci		priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTR] =
4528c2ecf20Sopenharmony_ci			(reg >> RG_AUDLORGAIN_SFT) & RG_AUDLORGAIN_MASK;
4538c2ecf20Sopenharmony_ci		break;
4548c2ecf20Sopenharmony_ci	case MT6358_ZCD_CON3:
4558c2ecf20Sopenharmony_ci		regmap_read(priv->regmap, MT6358_ZCD_CON3, &reg);
4568c2ecf20Sopenharmony_ci		priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTL] =
4578c2ecf20Sopenharmony_ci			(reg >> RG_AUDHSGAIN_SFT) & RG_AUDHSGAIN_MASK;
4588c2ecf20Sopenharmony_ci		priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTR] =
4598c2ecf20Sopenharmony_ci			(reg >> RG_AUDHSGAIN_SFT) & RG_AUDHSGAIN_MASK;
4608c2ecf20Sopenharmony_ci		break;
4618c2ecf20Sopenharmony_ci	case MT6358_AUDENC_ANA_CON0:
4628c2ecf20Sopenharmony_ci	case MT6358_AUDENC_ANA_CON1:
4638c2ecf20Sopenharmony_ci		regmap_read(priv->regmap, MT6358_AUDENC_ANA_CON0, &reg);
4648c2ecf20Sopenharmony_ci		priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1] =
4658c2ecf20Sopenharmony_ci			(reg >> RG_AUDPREAMPLGAIN_SFT) & RG_AUDPREAMPLGAIN_MASK;
4668c2ecf20Sopenharmony_ci		regmap_read(priv->regmap, MT6358_AUDENC_ANA_CON1, &reg);
4678c2ecf20Sopenharmony_ci		priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2] =
4688c2ecf20Sopenharmony_ci			(reg >> RG_AUDPREAMPRGAIN_SFT) & RG_AUDPREAMPRGAIN_MASK;
4698c2ecf20Sopenharmony_ci		break;
4708c2ecf20Sopenharmony_ci	}
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ci	return ret;
4738c2ecf20Sopenharmony_ci}
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_cistatic void mt6358_restore_pga(struct mt6358_priv *priv);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_cistatic int mt6358_enable_wov_phase2(struct mt6358_priv *priv)
4788c2ecf20Sopenharmony_ci{
4798c2ecf20Sopenharmony_ci	/* analog */
4808c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON13,
4818c2ecf20Sopenharmony_ci			   0xffff, 0x0000);
4828c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_DCXO_CW14, 0xffff, 0xa2b5);
4838c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
4848c2ecf20Sopenharmony_ci			   0xffff, 0x0800);
4858c2ecf20Sopenharmony_ci	mt6358_restore_pga(priv);
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_DCXO_CW13, 0xffff, 0x9929);
4888c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON9,
4898c2ecf20Sopenharmony_ci			   0xffff, 0x0025);
4908c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON8,
4918c2ecf20Sopenharmony_ci			   0xffff, 0x0005);
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci	/* digital */
4948c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUD_TOP_CKPDN_CON0,
4958c2ecf20Sopenharmony_ci			   0xffff, 0x0000);
4968c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE3, 0xffff, 0x0120);
4978c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG0, 0xffff, 0xffff);
4988c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG1, 0xffff, 0x0200);
4998c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG2, 0xffff, 0x2424);
5008c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG3, 0xffff, 0xdbac);
5018c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG4, 0xffff, 0x029e);
5028c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG5, 0xffff, 0x0000);
5038c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_POSDIV_CFG0,
5048c2ecf20Sopenharmony_ci			   0xffff, 0x0000);
5058c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_HPF_CFG0,
5068c2ecf20Sopenharmony_ci			   0xffff, 0x0451);
5078c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_TOP, 0xffff, 0x68d1);
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	return 0;
5108c2ecf20Sopenharmony_ci}
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_cistatic int mt6358_disable_wov_phase2(struct mt6358_priv *priv)
5138c2ecf20Sopenharmony_ci{
5148c2ecf20Sopenharmony_ci	/* digital */
5158c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_TOP, 0xffff, 0xc000);
5168c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_HPF_CFG0,
5178c2ecf20Sopenharmony_ci			   0xffff, 0x0450);
5188c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_POSDIV_CFG0,
5198c2ecf20Sopenharmony_ci			   0xffff, 0x0c00);
5208c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG5, 0xffff, 0x0100);
5218c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG4, 0xffff, 0x006c);
5228c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG3, 0xffff, 0xa879);
5238c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG2, 0xffff, 0x2323);
5248c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG1, 0xffff, 0x0400);
5258c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_VOW_CFG0, 0xffff, 0x0000);
5268c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_GPIO_MODE3, 0xffff, 0x02d8);
5278c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUD_TOP_CKPDN_CON0,
5288c2ecf20Sopenharmony_ci			   0xffff, 0x0000);
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci	/* analog */
5318c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON8,
5328c2ecf20Sopenharmony_ci			   0xffff, 0x0004);
5338c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON9,
5348c2ecf20Sopenharmony_ci			   0xffff, 0x0000);
5358c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_DCXO_CW13, 0xffff, 0x9829);
5368c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
5378c2ecf20Sopenharmony_ci			   0xffff, 0x0000);
5388c2ecf20Sopenharmony_ci	mt6358_restore_pga(priv);
5398c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_DCXO_CW14, 0xffff, 0xa2b5);
5408c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON13,
5418c2ecf20Sopenharmony_ci			   0xffff, 0x0010);
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ci	return 0;
5448c2ecf20Sopenharmony_ci}
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_cistatic int mt6358_get_wov(struct snd_kcontrol *kcontrol,
5478c2ecf20Sopenharmony_ci			  struct snd_ctl_elem_value *ucontrol)
5488c2ecf20Sopenharmony_ci{
5498c2ecf20Sopenharmony_ci	struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol);
5508c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(c);
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci	ucontrol->value.integer.value[0] = priv->wov_enabled;
5538c2ecf20Sopenharmony_ci	return 0;
5548c2ecf20Sopenharmony_ci}
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_cistatic int mt6358_put_wov(struct snd_kcontrol *kcontrol,
5578c2ecf20Sopenharmony_ci			  struct snd_ctl_elem_value *ucontrol)
5588c2ecf20Sopenharmony_ci{
5598c2ecf20Sopenharmony_ci	struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol);
5608c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(c);
5618c2ecf20Sopenharmony_ci	int enabled = ucontrol->value.integer.value[0];
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci	if (priv->wov_enabled != enabled) {
5648c2ecf20Sopenharmony_ci		if (enabled)
5658c2ecf20Sopenharmony_ci			mt6358_enable_wov_phase2(priv);
5668c2ecf20Sopenharmony_ci		else
5678c2ecf20Sopenharmony_ci			mt6358_disable_wov_phase2(priv);
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_ci		priv->wov_enabled = enabled;
5708c2ecf20Sopenharmony_ci	}
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci	return 0;
5738c2ecf20Sopenharmony_ci}
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(playback_tlv, -1000, 100, 0);
5768c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(pga_tlv, 0, 600, 0);
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new mt6358_snd_controls[] = {
5798c2ecf20Sopenharmony_ci	/* dl pga gain */
5808c2ecf20Sopenharmony_ci	SOC_DOUBLE_EXT_TLV("Headphone Volume",
5818c2ecf20Sopenharmony_ci			   MT6358_ZCD_CON2, 0, 7, 0x12, 1,
5828c2ecf20Sopenharmony_ci			   snd_soc_get_volsw, mt6358_put_volsw, playback_tlv),
5838c2ecf20Sopenharmony_ci	SOC_DOUBLE_EXT_TLV("Lineout Volume",
5848c2ecf20Sopenharmony_ci			   MT6358_ZCD_CON1, 0, 7, 0x12, 1,
5858c2ecf20Sopenharmony_ci			   snd_soc_get_volsw, mt6358_put_volsw, playback_tlv),
5868c2ecf20Sopenharmony_ci	SOC_SINGLE_EXT_TLV("Handset Volume",
5878c2ecf20Sopenharmony_ci			   MT6358_ZCD_CON3, 0, 0x12, 1,
5888c2ecf20Sopenharmony_ci			   snd_soc_get_volsw, mt6358_put_volsw, playback_tlv),
5898c2ecf20Sopenharmony_ci	/* ul pga gain */
5908c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_EXT_TLV("PGA Volume",
5918c2ecf20Sopenharmony_ci			     MT6358_AUDENC_ANA_CON0, MT6358_AUDENC_ANA_CON1,
5928c2ecf20Sopenharmony_ci			     8, 4, 0,
5938c2ecf20Sopenharmony_ci			     snd_soc_get_volsw, mt6358_put_volsw, pga_tlv),
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_ci	SOC_SINGLE_BOOL_EXT("Wake-on-Voice Phase2 Switch", 0,
5968c2ecf20Sopenharmony_ci			    mt6358_get_wov, mt6358_put_wov),
5978c2ecf20Sopenharmony_ci};
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci/* MUX */
6008c2ecf20Sopenharmony_ci/* LOL MUX */
6018c2ecf20Sopenharmony_cistatic const char * const lo_in_mux_map[] = {
6028c2ecf20Sopenharmony_ci	"Open", "Mute", "Playback", "Test Mode"
6038c2ecf20Sopenharmony_ci};
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_cistatic int lo_in_mux_map_value[] = {
6068c2ecf20Sopenharmony_ci	0x0, 0x1, 0x2, 0x3,
6078c2ecf20Sopenharmony_ci};
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(lo_in_mux_map_enum,
6108c2ecf20Sopenharmony_ci				  MT6358_AUDDEC_ANA_CON7,
6118c2ecf20Sopenharmony_ci				  RG_AUDLOLMUXINPUTSEL_VAUDP15_SFT,
6128c2ecf20Sopenharmony_ci				  RG_AUDLOLMUXINPUTSEL_VAUDP15_MASK,
6138c2ecf20Sopenharmony_ci				  lo_in_mux_map,
6148c2ecf20Sopenharmony_ci				  lo_in_mux_map_value);
6158c2ecf20Sopenharmony_ci
6168c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new lo_in_mux_control =
6178c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("In Select", lo_in_mux_map_enum);
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ci/*HP MUX */
6208c2ecf20Sopenharmony_cienum {
6218c2ecf20Sopenharmony_ci	HP_MUX_OPEN = 0,
6228c2ecf20Sopenharmony_ci	HP_MUX_HPSPK,
6238c2ecf20Sopenharmony_ci	HP_MUX_HP,
6248c2ecf20Sopenharmony_ci	HP_MUX_TEST_MODE,
6258c2ecf20Sopenharmony_ci	HP_MUX_HP_IMPEDANCE,
6268c2ecf20Sopenharmony_ci	HP_MUX_MASK = 0x7,
6278c2ecf20Sopenharmony_ci};
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_cistatic const char * const hp_in_mux_map[] = {
6308c2ecf20Sopenharmony_ci	"Open",
6318c2ecf20Sopenharmony_ci	"LoudSPK Playback",
6328c2ecf20Sopenharmony_ci	"Audio Playback",
6338c2ecf20Sopenharmony_ci	"Test Mode",
6348c2ecf20Sopenharmony_ci	"HP Impedance",
6358c2ecf20Sopenharmony_ci	"undefined1",
6368c2ecf20Sopenharmony_ci	"undefined2",
6378c2ecf20Sopenharmony_ci	"undefined3",
6388c2ecf20Sopenharmony_ci};
6398c2ecf20Sopenharmony_ci
6408c2ecf20Sopenharmony_cistatic int hp_in_mux_map_value[] = {
6418c2ecf20Sopenharmony_ci	HP_MUX_OPEN,
6428c2ecf20Sopenharmony_ci	HP_MUX_HPSPK,
6438c2ecf20Sopenharmony_ci	HP_MUX_HP,
6448c2ecf20Sopenharmony_ci	HP_MUX_TEST_MODE,
6458c2ecf20Sopenharmony_ci	HP_MUX_HP_IMPEDANCE,
6468c2ecf20Sopenharmony_ci	HP_MUX_OPEN,
6478c2ecf20Sopenharmony_ci	HP_MUX_OPEN,
6488c2ecf20Sopenharmony_ci	HP_MUX_OPEN,
6498c2ecf20Sopenharmony_ci};
6508c2ecf20Sopenharmony_ci
6518c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(hpl_in_mux_map_enum,
6528c2ecf20Sopenharmony_ci				  SND_SOC_NOPM,
6538c2ecf20Sopenharmony_ci				  0,
6548c2ecf20Sopenharmony_ci				  HP_MUX_MASK,
6558c2ecf20Sopenharmony_ci				  hp_in_mux_map,
6568c2ecf20Sopenharmony_ci				  hp_in_mux_map_value);
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hpl_in_mux_control =
6598c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("HPL Select", hpl_in_mux_map_enum);
6608c2ecf20Sopenharmony_ci
6618c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(hpr_in_mux_map_enum,
6628c2ecf20Sopenharmony_ci				  SND_SOC_NOPM,
6638c2ecf20Sopenharmony_ci				  0,
6648c2ecf20Sopenharmony_ci				  HP_MUX_MASK,
6658c2ecf20Sopenharmony_ci				  hp_in_mux_map,
6668c2ecf20Sopenharmony_ci				  hp_in_mux_map_value);
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hpr_in_mux_control =
6698c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("HPR Select", hpr_in_mux_map_enum);
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_ci/* RCV MUX */
6728c2ecf20Sopenharmony_cienum {
6738c2ecf20Sopenharmony_ci	RCV_MUX_OPEN = 0,
6748c2ecf20Sopenharmony_ci	RCV_MUX_MUTE,
6758c2ecf20Sopenharmony_ci	RCV_MUX_VOICE_PLAYBACK,
6768c2ecf20Sopenharmony_ci	RCV_MUX_TEST_MODE,
6778c2ecf20Sopenharmony_ci	RCV_MUX_MASK = 0x3,
6788c2ecf20Sopenharmony_ci};
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_cistatic const char * const rcv_in_mux_map[] = {
6818c2ecf20Sopenharmony_ci	"Open", "Mute", "Voice Playback", "Test Mode"
6828c2ecf20Sopenharmony_ci};
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_cistatic int rcv_in_mux_map_value[] = {
6858c2ecf20Sopenharmony_ci	RCV_MUX_OPEN,
6868c2ecf20Sopenharmony_ci	RCV_MUX_MUTE,
6878c2ecf20Sopenharmony_ci	RCV_MUX_VOICE_PLAYBACK,
6888c2ecf20Sopenharmony_ci	RCV_MUX_TEST_MODE,
6898c2ecf20Sopenharmony_ci};
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(rcv_in_mux_map_enum,
6928c2ecf20Sopenharmony_ci				  SND_SOC_NOPM,
6938c2ecf20Sopenharmony_ci				  0,
6948c2ecf20Sopenharmony_ci				  RCV_MUX_MASK,
6958c2ecf20Sopenharmony_ci				  rcv_in_mux_map,
6968c2ecf20Sopenharmony_ci				  rcv_in_mux_map_value);
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rcv_in_mux_control =
6998c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("RCV Select", rcv_in_mux_map_enum);
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci/* DAC In MUX */
7028c2ecf20Sopenharmony_cistatic const char * const dac_in_mux_map[] = {
7038c2ecf20Sopenharmony_ci	"Normal Path", "Sgen"
7048c2ecf20Sopenharmony_ci};
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_cistatic int dac_in_mux_map_value[] = {
7078c2ecf20Sopenharmony_ci	0x0, 0x1,
7088c2ecf20Sopenharmony_ci};
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(dac_in_mux_map_enum,
7118c2ecf20Sopenharmony_ci				  MT6358_AFE_TOP_CON0,
7128c2ecf20Sopenharmony_ci				  DL_SINE_ON_SFT,
7138c2ecf20Sopenharmony_ci				  DL_SINE_ON_MASK,
7148c2ecf20Sopenharmony_ci				  dac_in_mux_map,
7158c2ecf20Sopenharmony_ci				  dac_in_mux_map_value);
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new dac_in_mux_control =
7188c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("DAC Select", dac_in_mux_map_enum);
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_ci/* AIF Out MUX */
7218c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(aif_out_mux_map_enum,
7228c2ecf20Sopenharmony_ci				  MT6358_AFE_TOP_CON0,
7238c2ecf20Sopenharmony_ci				  UL_SINE_ON_SFT,
7248c2ecf20Sopenharmony_ci				  UL_SINE_ON_MASK,
7258c2ecf20Sopenharmony_ci				  dac_in_mux_map,
7268c2ecf20Sopenharmony_ci				  dac_in_mux_map_value);
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new aif_out_mux_control =
7298c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("AIF Out Select", aif_out_mux_map_enum);
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_ci/* Mic Type MUX */
7328c2ecf20Sopenharmony_cienum {
7338c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_IDLE = 0,
7348c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_ACC,
7358c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_DMIC,
7368c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_DCC,
7378c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_DCC_ECM_DIFF,
7388c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_DCC_ECM_SINGLE,
7398c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_MASK = 0x7,
7408c2ecf20Sopenharmony_ci};
7418c2ecf20Sopenharmony_ci
7428c2ecf20Sopenharmony_ci#define IS_DCC_BASE(type) ((type) == MIC_TYPE_MUX_DCC || \
7438c2ecf20Sopenharmony_ci			(type) == MIC_TYPE_MUX_DCC_ECM_DIFF || \
7448c2ecf20Sopenharmony_ci			(type) == MIC_TYPE_MUX_DCC_ECM_SINGLE)
7458c2ecf20Sopenharmony_ci
7468c2ecf20Sopenharmony_cistatic const char * const mic_type_mux_map[] = {
7478c2ecf20Sopenharmony_ci	"Idle",
7488c2ecf20Sopenharmony_ci	"ACC",
7498c2ecf20Sopenharmony_ci	"DMIC",
7508c2ecf20Sopenharmony_ci	"DCC",
7518c2ecf20Sopenharmony_ci	"DCC_ECM_DIFF",
7528c2ecf20Sopenharmony_ci	"DCC_ECM_SINGLE",
7538c2ecf20Sopenharmony_ci};
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_cistatic int mic_type_mux_map_value[] = {
7568c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_IDLE,
7578c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_ACC,
7588c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_DMIC,
7598c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_DCC,
7608c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_DCC_ECM_DIFF,
7618c2ecf20Sopenharmony_ci	MIC_TYPE_MUX_DCC_ECM_SINGLE,
7628c2ecf20Sopenharmony_ci};
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(mic_type_mux_map_enum,
7658c2ecf20Sopenharmony_ci				  SND_SOC_NOPM,
7668c2ecf20Sopenharmony_ci				  0,
7678c2ecf20Sopenharmony_ci				  MIC_TYPE_MUX_MASK,
7688c2ecf20Sopenharmony_ci				  mic_type_mux_map,
7698c2ecf20Sopenharmony_ci				  mic_type_mux_map_value);
7708c2ecf20Sopenharmony_ci
7718c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new mic_type_mux_control =
7728c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("Mic Type Select", mic_type_mux_map_enum);
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_ci/* ADC L MUX */
7758c2ecf20Sopenharmony_cienum {
7768c2ecf20Sopenharmony_ci	ADC_MUX_IDLE = 0,
7778c2ecf20Sopenharmony_ci	ADC_MUX_AIN0,
7788c2ecf20Sopenharmony_ci	ADC_MUX_PREAMPLIFIER,
7798c2ecf20Sopenharmony_ci	ADC_MUX_IDLE1,
7808c2ecf20Sopenharmony_ci	ADC_MUX_MASK = 0x3,
7818c2ecf20Sopenharmony_ci};
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_cistatic const char * const adc_left_mux_map[] = {
7848c2ecf20Sopenharmony_ci	"Idle", "AIN0", "Left Preamplifier", "Idle_1"
7858c2ecf20Sopenharmony_ci};
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_cistatic int adc_mux_map_value[] = {
7888c2ecf20Sopenharmony_ci	ADC_MUX_IDLE,
7898c2ecf20Sopenharmony_ci	ADC_MUX_AIN0,
7908c2ecf20Sopenharmony_ci	ADC_MUX_PREAMPLIFIER,
7918c2ecf20Sopenharmony_ci	ADC_MUX_IDLE1,
7928c2ecf20Sopenharmony_ci};
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(adc_left_mux_map_enum,
7958c2ecf20Sopenharmony_ci				  SND_SOC_NOPM,
7968c2ecf20Sopenharmony_ci				  0,
7978c2ecf20Sopenharmony_ci				  ADC_MUX_MASK,
7988c2ecf20Sopenharmony_ci				  adc_left_mux_map,
7998c2ecf20Sopenharmony_ci				  adc_mux_map_value);
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new adc_left_mux_control =
8028c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("ADC L Select", adc_left_mux_map_enum);
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_ci/* ADC R MUX */
8058c2ecf20Sopenharmony_cistatic const char * const adc_right_mux_map[] = {
8068c2ecf20Sopenharmony_ci	"Idle", "AIN0", "Right Preamplifier", "Idle_1"
8078c2ecf20Sopenharmony_ci};
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(adc_right_mux_map_enum,
8108c2ecf20Sopenharmony_ci				  SND_SOC_NOPM,
8118c2ecf20Sopenharmony_ci				  0,
8128c2ecf20Sopenharmony_ci				  ADC_MUX_MASK,
8138c2ecf20Sopenharmony_ci				  adc_right_mux_map,
8148c2ecf20Sopenharmony_ci				  adc_mux_map_value);
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new adc_right_mux_control =
8178c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("ADC R Select", adc_right_mux_map_enum);
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci/* PGA L MUX */
8208c2ecf20Sopenharmony_cienum {
8218c2ecf20Sopenharmony_ci	PGA_MUX_NONE = 0,
8228c2ecf20Sopenharmony_ci	PGA_MUX_AIN0,
8238c2ecf20Sopenharmony_ci	PGA_MUX_AIN1,
8248c2ecf20Sopenharmony_ci	PGA_MUX_AIN2,
8258c2ecf20Sopenharmony_ci	PGA_MUX_MASK = 0x3,
8268c2ecf20Sopenharmony_ci};
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_cistatic const char * const pga_mux_map[] = {
8298c2ecf20Sopenharmony_ci	"None", "AIN0", "AIN1", "AIN2"
8308c2ecf20Sopenharmony_ci};
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_cistatic int pga_mux_map_value[] = {
8338c2ecf20Sopenharmony_ci	PGA_MUX_NONE,
8348c2ecf20Sopenharmony_ci	PGA_MUX_AIN0,
8358c2ecf20Sopenharmony_ci	PGA_MUX_AIN1,
8368c2ecf20Sopenharmony_ci	PGA_MUX_AIN2,
8378c2ecf20Sopenharmony_ci};
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(pga_left_mux_map_enum,
8408c2ecf20Sopenharmony_ci				  SND_SOC_NOPM,
8418c2ecf20Sopenharmony_ci				  0,
8428c2ecf20Sopenharmony_ci				  PGA_MUX_MASK,
8438c2ecf20Sopenharmony_ci				  pga_mux_map,
8448c2ecf20Sopenharmony_ci				  pga_mux_map_value);
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new pga_left_mux_control =
8478c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("PGA L Select", pga_left_mux_map_enum);
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_ci/* PGA R MUX */
8508c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(pga_right_mux_map_enum,
8518c2ecf20Sopenharmony_ci				  SND_SOC_NOPM,
8528c2ecf20Sopenharmony_ci				  0,
8538c2ecf20Sopenharmony_ci				  PGA_MUX_MASK,
8548c2ecf20Sopenharmony_ci				  pga_mux_map,
8558c2ecf20Sopenharmony_ci				  pga_mux_map_value);
8568c2ecf20Sopenharmony_ci
8578c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new pga_right_mux_control =
8588c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("PGA R Select", pga_right_mux_map_enum);
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_cistatic int mt_clksq_event(struct snd_soc_dapm_widget *w,
8618c2ecf20Sopenharmony_ci			  struct snd_kcontrol *kcontrol,
8628c2ecf20Sopenharmony_ci			  int event)
8638c2ecf20Sopenharmony_ci{
8648c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
8658c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
8668c2ecf20Sopenharmony_ci
8678c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event);
8688c2ecf20Sopenharmony_ci
8698c2ecf20Sopenharmony_ci	switch (event) {
8708c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
8718c2ecf20Sopenharmony_ci		/* audio clk source from internal dcxo */
8728c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON6,
8738c2ecf20Sopenharmony_ci				   RG_CLKSQ_IN_SEL_TEST_MASK_SFT,
8748c2ecf20Sopenharmony_ci				   0x0);
8758c2ecf20Sopenharmony_ci		break;
8768c2ecf20Sopenharmony_ci	default:
8778c2ecf20Sopenharmony_ci		break;
8788c2ecf20Sopenharmony_ci	}
8798c2ecf20Sopenharmony_ci
8808c2ecf20Sopenharmony_ci	return 0;
8818c2ecf20Sopenharmony_ci}
8828c2ecf20Sopenharmony_ci
8838c2ecf20Sopenharmony_cistatic int mt_sgen_event(struct snd_soc_dapm_widget *w,
8848c2ecf20Sopenharmony_ci			 struct snd_kcontrol *kcontrol,
8858c2ecf20Sopenharmony_ci			 int event)
8868c2ecf20Sopenharmony_ci{
8878c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
8888c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
8898c2ecf20Sopenharmony_ci
8908c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event = 0x%x\n", __func__, event);
8918c2ecf20Sopenharmony_ci
8928c2ecf20Sopenharmony_ci	switch (event) {
8938c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
8948c2ecf20Sopenharmony_ci		/* sdm audio fifo clock power on */
8958c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON2, 0x0006);
8968c2ecf20Sopenharmony_ci		/* scrambler clock on enable */
8978c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON0, 0xCBA1);
8988c2ecf20Sopenharmony_ci		/* sdm power on */
8998c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON2, 0x0003);
9008c2ecf20Sopenharmony_ci		/* sdm fifo enable */
9018c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON2, 0x000B);
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AFE_SGEN_CFG0,
9048c2ecf20Sopenharmony_ci				   0xff3f,
9058c2ecf20Sopenharmony_ci				   0x0000);
9068c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AFE_SGEN_CFG1,
9078c2ecf20Sopenharmony_ci				   0xffff,
9088c2ecf20Sopenharmony_ci				   0x0001);
9098c2ecf20Sopenharmony_ci		break;
9108c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
9118c2ecf20Sopenharmony_ci		/* DL scrambler disabling sequence */
9128c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON2, 0x0000);
9138c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON0, 0xcba0);
9148c2ecf20Sopenharmony_ci		break;
9158c2ecf20Sopenharmony_ci	default:
9168c2ecf20Sopenharmony_ci		break;
9178c2ecf20Sopenharmony_ci	}
9188c2ecf20Sopenharmony_ci
9198c2ecf20Sopenharmony_ci	return 0;
9208c2ecf20Sopenharmony_ci}
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_cistatic int mt_aif_in_event(struct snd_soc_dapm_widget *w,
9238c2ecf20Sopenharmony_ci			   struct snd_kcontrol *kcontrol,
9248c2ecf20Sopenharmony_ci			   int event)
9258c2ecf20Sopenharmony_ci{
9268c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
9278c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
9288c2ecf20Sopenharmony_ci
9298c2ecf20Sopenharmony_ci	dev_info(priv->dev, "%s(), event 0x%x, rate %d\n",
9308c2ecf20Sopenharmony_ci		 __func__, event, priv->dl_rate);
9318c2ecf20Sopenharmony_ci
9328c2ecf20Sopenharmony_ci	switch (event) {
9338c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
9348c2ecf20Sopenharmony_ci		playback_gpio_set(priv);
9358c2ecf20Sopenharmony_ci
9368c2ecf20Sopenharmony_ci		/* sdm audio fifo clock power on */
9378c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON2, 0x0006);
9388c2ecf20Sopenharmony_ci		/* scrambler clock on enable */
9398c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON0, 0xCBA1);
9408c2ecf20Sopenharmony_ci		/* sdm power on */
9418c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON2, 0x0003);
9428c2ecf20Sopenharmony_ci		/* sdm fifo enable */
9438c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON2, 0x000B);
9448c2ecf20Sopenharmony_ci		break;
9458c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
9468c2ecf20Sopenharmony_ci		/* DL scrambler disabling sequence */
9478c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON2, 0x0000);
9488c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFUNC_AUD_CON0, 0xcba0);
9498c2ecf20Sopenharmony_ci
9508c2ecf20Sopenharmony_ci		playback_gpio_reset(priv);
9518c2ecf20Sopenharmony_ci		break;
9528c2ecf20Sopenharmony_ci	default:
9538c2ecf20Sopenharmony_ci		break;
9548c2ecf20Sopenharmony_ci	}
9558c2ecf20Sopenharmony_ci
9568c2ecf20Sopenharmony_ci	return 0;
9578c2ecf20Sopenharmony_ci}
9588c2ecf20Sopenharmony_ci
9598c2ecf20Sopenharmony_cistatic int mtk_hp_enable(struct mt6358_priv *priv)
9608c2ecf20Sopenharmony_ci{
9618c2ecf20Sopenharmony_ci	/* Pull-down HPL/R to AVSS28_AUD */
9628c2ecf20Sopenharmony_ci	hp_pull_down(priv, true);
9638c2ecf20Sopenharmony_ci	/* release HP CMFB gate rstb */
9648c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON4,
9658c2ecf20Sopenharmony_ci			   0x1 << 6, 0x1 << 6);
9668c2ecf20Sopenharmony_ci
9678c2ecf20Sopenharmony_ci	/* Reduce ESD resistance of AU_REFN */
9688c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON2, 0x4000);
9698c2ecf20Sopenharmony_ci
9708c2ecf20Sopenharmony_ci	/* Set HPR/HPL gain as minimum (~ -40dB) */
9718c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_ZCD_CON2, DL_GAIN_N_40DB_REG);
9728c2ecf20Sopenharmony_ci
9738c2ecf20Sopenharmony_ci	/* Turn on DA_600K_NCP_VA18 */
9748c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON1, 0x0001);
9758c2ecf20Sopenharmony_ci	/* Set NCP clock as 604kHz // 26MHz/43 = 604KHz */
9768c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON2, 0x002c);
9778c2ecf20Sopenharmony_ci	/* Toggle RG_DIVCKS_CHG */
9788c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON0, 0x0001);
9798c2ecf20Sopenharmony_ci	/* Set NCP soft start mode as default mode: 100us */
9808c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON4, 0x0003);
9818c2ecf20Sopenharmony_ci	/* Enable NCP */
9828c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON3, 0x0000);
9838c2ecf20Sopenharmony_ci	usleep_range(250, 270);
9848c2ecf20Sopenharmony_ci
9858c2ecf20Sopenharmony_ci	/* Enable cap-less LDOs (1.5V) */
9868c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON14,
9878c2ecf20Sopenharmony_ci			   0x1055, 0x1055);
9888c2ecf20Sopenharmony_ci	/* Enable NV regulator (-1.2V) */
9898c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON15, 0x0001);
9908c2ecf20Sopenharmony_ci	usleep_range(100, 120);
9918c2ecf20Sopenharmony_ci
9928c2ecf20Sopenharmony_ci	/* Disable AUD_ZCD */
9938c2ecf20Sopenharmony_ci	hp_zcd_disable(priv);
9948c2ecf20Sopenharmony_ci
9958c2ecf20Sopenharmony_ci	/* Disable headphone short-circuit protection */
9968c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x3000);
9978c2ecf20Sopenharmony_ci
9988c2ecf20Sopenharmony_ci	/* Enable IBIST */
9998c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON12, 0x0055);
10008c2ecf20Sopenharmony_ci
10018c2ecf20Sopenharmony_ci	/* Set HP DR bias current optimization, 010: 6uA */
10028c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON11, 0x4900);
10038c2ecf20Sopenharmony_ci	/* Set HP & ZCD bias current optimization */
10048c2ecf20Sopenharmony_ci	/* 01: ZCD: 4uA, HP/HS/LO: 5uA */
10058c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON12, 0x0055);
10068c2ecf20Sopenharmony_ci	/* Set HPP/N STB enhance circuits */
10078c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON2, 0x4033);
10088c2ecf20Sopenharmony_ci
10098c2ecf20Sopenharmony_ci	/* Enable HP aux output stage */
10108c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x000c);
10118c2ecf20Sopenharmony_ci	/* Enable HP aux feedback loop */
10128c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x003c);
10138c2ecf20Sopenharmony_ci	/* Enable HP aux CMFB loop */
10148c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON9, 0x0c00);
10158c2ecf20Sopenharmony_ci	/* Enable HP driver bias circuits */
10168c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x30c0);
10178c2ecf20Sopenharmony_ci	/* Enable HP driver core circuits */
10188c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x30f0);
10198c2ecf20Sopenharmony_ci	/* Short HP main output to HP aux output stage */
10208c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x00fc);
10218c2ecf20Sopenharmony_ci
10228c2ecf20Sopenharmony_ci	/* Enable HP main CMFB loop */
10238c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON9, 0x0e00);
10248c2ecf20Sopenharmony_ci	/* Disable HP aux CMFB loop */
10258c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON9, 0x0200);
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_ci	/* Select CMFB resistor bulk to AC mode */
10288c2ecf20Sopenharmony_ci	/* Selec HS/LO cap size (6.5pF default) */
10298c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON10, 0x0000);
10308c2ecf20Sopenharmony_ci
10318c2ecf20Sopenharmony_ci	/* Enable HP main output stage */
10328c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x00ff);
10338c2ecf20Sopenharmony_ci	/* Enable HPR/L main output stage step by step */
10348c2ecf20Sopenharmony_ci	hp_main_output_ramp(priv, true);
10358c2ecf20Sopenharmony_ci
10368c2ecf20Sopenharmony_ci	/* Reduce HP aux feedback loop gain */
10378c2ecf20Sopenharmony_ci	hp_aux_feedback_loop_gain_ramp(priv, true);
10388c2ecf20Sopenharmony_ci	/* Disable HP aux feedback loop */
10398c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x3fcf);
10408c2ecf20Sopenharmony_ci
10418c2ecf20Sopenharmony_ci	/* apply volume setting */
10428c2ecf20Sopenharmony_ci	headset_volume_ramp(priv,
10438c2ecf20Sopenharmony_ci			    DL_GAIN_N_10DB,
10448c2ecf20Sopenharmony_ci			    priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL]);
10458c2ecf20Sopenharmony_ci
10468c2ecf20Sopenharmony_ci	/* Disable HP aux output stage */
10478c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x3fc3);
10488c2ecf20Sopenharmony_ci	/* Unshort HP main output to HP aux output stage */
10498c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x3f03);
10508c2ecf20Sopenharmony_ci	usleep_range(100, 120);
10518c2ecf20Sopenharmony_ci
10528c2ecf20Sopenharmony_ci	/* Enable AUD_CLK */
10538c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON13, 0x1, 0x1);
10548c2ecf20Sopenharmony_ci	/* Enable Audio DAC  */
10558c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x30ff);
10568c2ecf20Sopenharmony_ci	/* Enable low-noise mode of DAC */
10578c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON9, 0xf201);
10588c2ecf20Sopenharmony_ci	usleep_range(100, 120);
10598c2ecf20Sopenharmony_ci
10608c2ecf20Sopenharmony_ci	/* Switch HPL MUX to audio DAC */
10618c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x32ff);
10628c2ecf20Sopenharmony_ci	/* Switch HPR MUX to audio DAC */
10638c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x3aff);
10648c2ecf20Sopenharmony_ci
10658c2ecf20Sopenharmony_ci	/* Disable Pull-down HPL/R to AVSS28_AUD */
10668c2ecf20Sopenharmony_ci	hp_pull_down(priv, false);
10678c2ecf20Sopenharmony_ci
10688c2ecf20Sopenharmony_ci	return 0;
10698c2ecf20Sopenharmony_ci}
10708c2ecf20Sopenharmony_ci
10718c2ecf20Sopenharmony_cistatic int mtk_hp_disable(struct mt6358_priv *priv)
10728c2ecf20Sopenharmony_ci{
10738c2ecf20Sopenharmony_ci	/* Pull-down HPL/R to AVSS28_AUD */
10748c2ecf20Sopenharmony_ci	hp_pull_down(priv, true);
10758c2ecf20Sopenharmony_ci
10768c2ecf20Sopenharmony_ci	/* HPR/HPL mux to open */
10778c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON0,
10788c2ecf20Sopenharmony_ci			   0x0f00, 0x0000);
10798c2ecf20Sopenharmony_ci
10808c2ecf20Sopenharmony_ci	/* Disable low-noise mode of DAC */
10818c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON9,
10828c2ecf20Sopenharmony_ci			   0x0001, 0x0000);
10838c2ecf20Sopenharmony_ci
10848c2ecf20Sopenharmony_ci	/* Disable Audio DAC */
10858c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON0,
10868c2ecf20Sopenharmony_ci			   0x000f, 0x0000);
10878c2ecf20Sopenharmony_ci
10888c2ecf20Sopenharmony_ci	/* Disable AUD_CLK */
10898c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON13, 0x1, 0x0);
10908c2ecf20Sopenharmony_ci
10918c2ecf20Sopenharmony_ci	/* Short HP main output to HP aux output stage */
10928c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x3fc3);
10938c2ecf20Sopenharmony_ci	/* Enable HP aux output stage */
10948c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x3fcf);
10958c2ecf20Sopenharmony_ci
10968c2ecf20Sopenharmony_ci	/* decrease HPL/R gain to normal gain step by step */
10978c2ecf20Sopenharmony_ci	headset_volume_ramp(priv,
10988c2ecf20Sopenharmony_ci			    priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL],
10998c2ecf20Sopenharmony_ci			    DL_GAIN_N_40DB);
11008c2ecf20Sopenharmony_ci
11018c2ecf20Sopenharmony_ci	/* Enable HP aux feedback loop */
11028c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x3fff);
11038c2ecf20Sopenharmony_ci
11048c2ecf20Sopenharmony_ci	/* Reduce HP aux feedback loop gain */
11058c2ecf20Sopenharmony_ci	hp_aux_feedback_loop_gain_ramp(priv, false);
11068c2ecf20Sopenharmony_ci
11078c2ecf20Sopenharmony_ci	/* decrease HPR/L main output stage step by step */
11088c2ecf20Sopenharmony_ci	hp_main_output_ramp(priv, false);
11098c2ecf20Sopenharmony_ci
11108c2ecf20Sopenharmony_ci	/* Disable HP main output stage */
11118c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x3, 0x0);
11128c2ecf20Sopenharmony_ci
11138c2ecf20Sopenharmony_ci	/* Enable HP aux CMFB loop */
11148c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON9, 0x0e00);
11158c2ecf20Sopenharmony_ci
11168c2ecf20Sopenharmony_ci	/* Disable HP main CMFB loop */
11178c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON9, 0x0c00);
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_ci	/* Unshort HP main output to HP aux output stage */
11208c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON1,
11218c2ecf20Sopenharmony_ci			   0x3 << 6, 0x0);
11228c2ecf20Sopenharmony_ci
11238c2ecf20Sopenharmony_ci	/* Disable HP driver core circuits */
11248c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON0,
11258c2ecf20Sopenharmony_ci			   0x3 << 4, 0x0);
11268c2ecf20Sopenharmony_ci
11278c2ecf20Sopenharmony_ci	/* Disable HP driver bias circuits */
11288c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON0,
11298c2ecf20Sopenharmony_ci			   0x3 << 6, 0x0);
11308c2ecf20Sopenharmony_ci
11318c2ecf20Sopenharmony_ci	/* Disable HP aux CMFB loop */
11328c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON9, 0x0000);
11338c2ecf20Sopenharmony_ci
11348c2ecf20Sopenharmony_ci	/* Disable HP aux feedback loop */
11358c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON1,
11368c2ecf20Sopenharmony_ci			   0x3 << 4, 0x0);
11378c2ecf20Sopenharmony_ci
11388c2ecf20Sopenharmony_ci	/* Disable HP aux output stage */
11398c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON1,
11408c2ecf20Sopenharmony_ci			   0x3 << 2, 0x0);
11418c2ecf20Sopenharmony_ci
11428c2ecf20Sopenharmony_ci	/* Disable IBIST */
11438c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON12,
11448c2ecf20Sopenharmony_ci			   0x1 << 8, 0x1 << 8);
11458c2ecf20Sopenharmony_ci
11468c2ecf20Sopenharmony_ci	/* Disable NV regulator (-1.2V) */
11478c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON15, 0x1, 0x0);
11488c2ecf20Sopenharmony_ci	/* Disable cap-less LDOs (1.5V) */
11498c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON14,
11508c2ecf20Sopenharmony_ci			   0x1055, 0x0);
11518c2ecf20Sopenharmony_ci	/* Disable NCP */
11528c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDNCP_CLKDIV_CON3,
11538c2ecf20Sopenharmony_ci			   0x1, 0x1);
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci	/* Increase ESD resistance of AU_REFN */
11568c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON2,
11578c2ecf20Sopenharmony_ci			   0x1 << 14, 0x0);
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_ci	/* Set HP CMFB gate rstb */
11608c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON4,
11618c2ecf20Sopenharmony_ci			   0x1 << 6, 0x0);
11628c2ecf20Sopenharmony_ci	/* disable Pull-down HPL/R to AVSS28_AUD */
11638c2ecf20Sopenharmony_ci	hp_pull_down(priv, false);
11648c2ecf20Sopenharmony_ci
11658c2ecf20Sopenharmony_ci	return 0;
11668c2ecf20Sopenharmony_ci}
11678c2ecf20Sopenharmony_ci
11688c2ecf20Sopenharmony_cistatic int mtk_hp_spk_enable(struct mt6358_priv *priv)
11698c2ecf20Sopenharmony_ci{
11708c2ecf20Sopenharmony_ci	/* Pull-down HPL/R to AVSS28_AUD */
11718c2ecf20Sopenharmony_ci	hp_pull_down(priv, true);
11728c2ecf20Sopenharmony_ci	/* release HP CMFB gate rstb */
11738c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON4,
11748c2ecf20Sopenharmony_ci			   0x1 << 6, 0x1 << 6);
11758c2ecf20Sopenharmony_ci
11768c2ecf20Sopenharmony_ci	/* Reduce ESD resistance of AU_REFN */
11778c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON2, 0x4000);
11788c2ecf20Sopenharmony_ci
11798c2ecf20Sopenharmony_ci	/* Set HPR/HPL gain to -10dB */
11808c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_ZCD_CON2, DL_GAIN_N_10DB_REG);
11818c2ecf20Sopenharmony_ci
11828c2ecf20Sopenharmony_ci	/* Turn on DA_600K_NCP_VA18 */
11838c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON1, 0x0001);
11848c2ecf20Sopenharmony_ci	/* Set NCP clock as 604kHz // 26MHz/43 = 604KHz */
11858c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON2, 0x002c);
11868c2ecf20Sopenharmony_ci	/* Toggle RG_DIVCKS_CHG */
11878c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON0, 0x0001);
11888c2ecf20Sopenharmony_ci	/* Set NCP soft start mode as default mode: 100us */
11898c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON4, 0x0003);
11908c2ecf20Sopenharmony_ci	/* Enable NCP */
11918c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON3, 0x0000);
11928c2ecf20Sopenharmony_ci	usleep_range(250, 270);
11938c2ecf20Sopenharmony_ci
11948c2ecf20Sopenharmony_ci	/* Enable cap-less LDOs (1.5V) */
11958c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON14,
11968c2ecf20Sopenharmony_ci			   0x1055, 0x1055);
11978c2ecf20Sopenharmony_ci	/* Enable NV regulator (-1.2V) */
11988c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON15, 0x0001);
11998c2ecf20Sopenharmony_ci	usleep_range(100, 120);
12008c2ecf20Sopenharmony_ci
12018c2ecf20Sopenharmony_ci	/* Disable AUD_ZCD */
12028c2ecf20Sopenharmony_ci	hp_zcd_disable(priv);
12038c2ecf20Sopenharmony_ci
12048c2ecf20Sopenharmony_ci	/* Disable headphone short-circuit protection */
12058c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x3000);
12068c2ecf20Sopenharmony_ci
12078c2ecf20Sopenharmony_ci	/* Enable IBIST */
12088c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON12, 0x0055);
12098c2ecf20Sopenharmony_ci
12108c2ecf20Sopenharmony_ci	/* Set HP DR bias current optimization, 010: 6uA */
12118c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON11, 0x4900);
12128c2ecf20Sopenharmony_ci	/* Set HP & ZCD bias current optimization */
12138c2ecf20Sopenharmony_ci	/* 01: ZCD: 4uA, HP/HS/LO: 5uA */
12148c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON12, 0x0055);
12158c2ecf20Sopenharmony_ci	/* Set HPP/N STB enhance circuits */
12168c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON2, 0x4033);
12178c2ecf20Sopenharmony_ci
12188c2ecf20Sopenharmony_ci	/* Disable Pull-down HPL/R to AVSS28_AUD */
12198c2ecf20Sopenharmony_ci	hp_pull_down(priv, false);
12208c2ecf20Sopenharmony_ci
12218c2ecf20Sopenharmony_ci	/* Enable HP driver bias circuits */
12228c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x30c0);
12238c2ecf20Sopenharmony_ci	/* Enable HP driver core circuits */
12248c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x30f0);
12258c2ecf20Sopenharmony_ci	/* Enable HP main CMFB loop */
12268c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON9, 0x0200);
12278c2ecf20Sopenharmony_ci
12288c2ecf20Sopenharmony_ci	/* Select CMFB resistor bulk to AC mode */
12298c2ecf20Sopenharmony_ci	/* Selec HS/LO cap size (6.5pF default) */
12308c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON10, 0x0000);
12318c2ecf20Sopenharmony_ci
12328c2ecf20Sopenharmony_ci	/* Enable HP main output stage */
12338c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x0003);
12348c2ecf20Sopenharmony_ci	/* Enable HPR/L main output stage step by step */
12358c2ecf20Sopenharmony_ci	hp_main_output_ramp(priv, true);
12368c2ecf20Sopenharmony_ci
12378c2ecf20Sopenharmony_ci	/* Set LO gain as minimum (~ -40dB) */
12388c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_ZCD_CON1, DL_GAIN_N_40DB_REG);
12398c2ecf20Sopenharmony_ci	/* apply volume setting */
12408c2ecf20Sopenharmony_ci	headset_volume_ramp(priv,
12418c2ecf20Sopenharmony_ci			    DL_GAIN_N_10DB,
12428c2ecf20Sopenharmony_ci			    priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL]);
12438c2ecf20Sopenharmony_ci
12448c2ecf20Sopenharmony_ci	/* Set LO STB enhance circuits */
12458c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON7, 0x0110);
12468c2ecf20Sopenharmony_ci	/* Enable LO driver bias circuits */
12478c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON7, 0x0112);
12488c2ecf20Sopenharmony_ci	/* Enable LO driver core circuits */
12498c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON7, 0x0113);
12508c2ecf20Sopenharmony_ci
12518c2ecf20Sopenharmony_ci	/* Set LOL gain to normal gain step by step */
12528c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_ZCD_CON1,
12538c2ecf20Sopenharmony_ci			   RG_AUDLOLGAIN_MASK_SFT,
12548c2ecf20Sopenharmony_ci			   priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTL] <<
12558c2ecf20Sopenharmony_ci			   RG_AUDLOLGAIN_SFT);
12568c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_ZCD_CON1,
12578c2ecf20Sopenharmony_ci			   RG_AUDLORGAIN_MASK_SFT,
12588c2ecf20Sopenharmony_ci			   priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTR] <<
12598c2ecf20Sopenharmony_ci			   RG_AUDLORGAIN_SFT);
12608c2ecf20Sopenharmony_ci
12618c2ecf20Sopenharmony_ci	/* Enable AUD_CLK */
12628c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON13, 0x1, 0x1);
12638c2ecf20Sopenharmony_ci	/* Enable Audio DAC  */
12648c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x30f9);
12658c2ecf20Sopenharmony_ci	/* Enable low-noise mode of DAC */
12668c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON9, 0x0201);
12678c2ecf20Sopenharmony_ci	/* Switch LOL MUX to audio DAC */
12688c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON7, 0x011b);
12698c2ecf20Sopenharmony_ci	/* Switch HPL/R MUX to Line-out */
12708c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x35f9);
12718c2ecf20Sopenharmony_ci
12728c2ecf20Sopenharmony_ci	return 0;
12738c2ecf20Sopenharmony_ci}
12748c2ecf20Sopenharmony_ci
12758c2ecf20Sopenharmony_cistatic int mtk_hp_spk_disable(struct mt6358_priv *priv)
12768c2ecf20Sopenharmony_ci{
12778c2ecf20Sopenharmony_ci	/* HPR/HPL mux to open */
12788c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON0,
12798c2ecf20Sopenharmony_ci			   0x0f00, 0x0000);
12808c2ecf20Sopenharmony_ci	/* LOL mux to open */
12818c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON7,
12828c2ecf20Sopenharmony_ci			   0x3 << 2, 0x0000);
12838c2ecf20Sopenharmony_ci
12848c2ecf20Sopenharmony_ci	/* Disable Audio DAC */
12858c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON0,
12868c2ecf20Sopenharmony_ci			   0x000f, 0x0000);
12878c2ecf20Sopenharmony_ci
12888c2ecf20Sopenharmony_ci	/* Disable AUD_CLK */
12898c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON13, 0x1, 0x0);
12908c2ecf20Sopenharmony_ci
12918c2ecf20Sopenharmony_ci	/* decrease HPL/R gain to normal gain step by step */
12928c2ecf20Sopenharmony_ci	headset_volume_ramp(priv,
12938c2ecf20Sopenharmony_ci			    priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL],
12948c2ecf20Sopenharmony_ci			    DL_GAIN_N_40DB);
12958c2ecf20Sopenharmony_ci
12968c2ecf20Sopenharmony_ci	/* decrease LOL gain to minimum gain step by step */
12978c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_ZCD_CON1,
12988c2ecf20Sopenharmony_ci			   DL_GAIN_REG_MASK, DL_GAIN_N_40DB_REG);
12998c2ecf20Sopenharmony_ci
13008c2ecf20Sopenharmony_ci	/* decrease HPR/L main output stage step by step */
13018c2ecf20Sopenharmony_ci	hp_main_output_ramp(priv, false);
13028c2ecf20Sopenharmony_ci
13038c2ecf20Sopenharmony_ci	/* Disable HP main output stage */
13048c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x3, 0x0);
13058c2ecf20Sopenharmony_ci
13068c2ecf20Sopenharmony_ci	/* Short HP main output to HP aux output stage */
13078c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x3fc3);
13088c2ecf20Sopenharmony_ci	/* Enable HP aux output stage */
13098c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x3fcf);
13108c2ecf20Sopenharmony_ci
13118c2ecf20Sopenharmony_ci	/* Enable HP aux feedback loop */
13128c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON1, 0x3fff);
13138c2ecf20Sopenharmony_ci
13148c2ecf20Sopenharmony_ci	/* Reduce HP aux feedback loop gain */
13158c2ecf20Sopenharmony_ci	hp_aux_feedback_loop_gain_ramp(priv, false);
13168c2ecf20Sopenharmony_ci
13178c2ecf20Sopenharmony_ci	/* Disable HP driver core circuits */
13188c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON0,
13198c2ecf20Sopenharmony_ci			   0x3 << 4, 0x0);
13208c2ecf20Sopenharmony_ci	/* Disable LO driver core circuits */
13218c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON7,
13228c2ecf20Sopenharmony_ci			   0x1, 0x0);
13238c2ecf20Sopenharmony_ci
13248c2ecf20Sopenharmony_ci	/* Disable HP driver bias circuits */
13258c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON0,
13268c2ecf20Sopenharmony_ci			   0x3 << 6, 0x0);
13278c2ecf20Sopenharmony_ci	/* Disable LO driver bias circuits */
13288c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON7,
13298c2ecf20Sopenharmony_ci			   0x1 << 1, 0x0);
13308c2ecf20Sopenharmony_ci
13318c2ecf20Sopenharmony_ci	/* Disable HP aux CMFB loop */
13328c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON9,
13338c2ecf20Sopenharmony_ci			   0xff << 8, 0x0000);
13348c2ecf20Sopenharmony_ci
13358c2ecf20Sopenharmony_ci	/* Disable IBIST */
13368c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON12,
13378c2ecf20Sopenharmony_ci			   0x1 << 8, 0x1 << 8);
13388c2ecf20Sopenharmony_ci	/* Disable NV regulator (-1.2V) */
13398c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON15, 0x1, 0x0);
13408c2ecf20Sopenharmony_ci	/* Disable cap-less LDOs (1.5V) */
13418c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON14, 0x1055, 0x0);
13428c2ecf20Sopenharmony_ci	/* Disable NCP */
13438c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDNCP_CLKDIV_CON3, 0x1, 0x1);
13448c2ecf20Sopenharmony_ci
13458c2ecf20Sopenharmony_ci	/* Set HP CMFB gate rstb */
13468c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON4,
13478c2ecf20Sopenharmony_ci			   0x1 << 6, 0x0);
13488c2ecf20Sopenharmony_ci	/* disable Pull-down HPL/R to AVSS28_AUD */
13498c2ecf20Sopenharmony_ci	hp_pull_down(priv, false);
13508c2ecf20Sopenharmony_ci
13518c2ecf20Sopenharmony_ci	return 0;
13528c2ecf20Sopenharmony_ci}
13538c2ecf20Sopenharmony_ci
13548c2ecf20Sopenharmony_cistatic int mt_hp_event(struct snd_soc_dapm_widget *w,
13558c2ecf20Sopenharmony_ci		       struct snd_kcontrol *kcontrol,
13568c2ecf20Sopenharmony_ci		       int event)
13578c2ecf20Sopenharmony_ci{
13588c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
13598c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
13608c2ecf20Sopenharmony_ci	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
13618c2ecf20Sopenharmony_ci	int device = DEVICE_HP;
13628c2ecf20Sopenharmony_ci
13638c2ecf20Sopenharmony_ci	dev_info(priv->dev, "%s(), event 0x%x, dev_counter[DEV_HP] %d, mux %u\n",
13648c2ecf20Sopenharmony_ci		 __func__,
13658c2ecf20Sopenharmony_ci		 event,
13668c2ecf20Sopenharmony_ci		 priv->dev_counter[device],
13678c2ecf20Sopenharmony_ci		 mux);
13688c2ecf20Sopenharmony_ci
13698c2ecf20Sopenharmony_ci	switch (event) {
13708c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
13718c2ecf20Sopenharmony_ci		priv->dev_counter[device]++;
13728c2ecf20Sopenharmony_ci		if (priv->dev_counter[device] > 1)
13738c2ecf20Sopenharmony_ci			break;	/* already enabled, do nothing */
13748c2ecf20Sopenharmony_ci		else if (priv->dev_counter[device] <= 0)
13758c2ecf20Sopenharmony_ci			dev_warn(priv->dev, "%s(), dev_counter[DEV_HP] %d <= 0\n",
13768c2ecf20Sopenharmony_ci				 __func__,
13778c2ecf20Sopenharmony_ci				 priv->dev_counter[device]);
13788c2ecf20Sopenharmony_ci
13798c2ecf20Sopenharmony_ci		priv->mux_select[MUX_HP_L] = mux;
13808c2ecf20Sopenharmony_ci
13818c2ecf20Sopenharmony_ci		if (mux == HP_MUX_HP)
13828c2ecf20Sopenharmony_ci			mtk_hp_enable(priv);
13838c2ecf20Sopenharmony_ci		else if (mux == HP_MUX_HPSPK)
13848c2ecf20Sopenharmony_ci			mtk_hp_spk_enable(priv);
13858c2ecf20Sopenharmony_ci		break;
13868c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMD:
13878c2ecf20Sopenharmony_ci		priv->dev_counter[device]--;
13888c2ecf20Sopenharmony_ci		if (priv->dev_counter[device] > 0) {
13898c2ecf20Sopenharmony_ci			break;	/* still being used, don't close */
13908c2ecf20Sopenharmony_ci		} else if (priv->dev_counter[device] < 0) {
13918c2ecf20Sopenharmony_ci			dev_warn(priv->dev, "%s(), dev_counter[DEV_HP] %d < 0\n",
13928c2ecf20Sopenharmony_ci				 __func__,
13938c2ecf20Sopenharmony_ci				 priv->dev_counter[device]);
13948c2ecf20Sopenharmony_ci			priv->dev_counter[device] = 0;
13958c2ecf20Sopenharmony_ci			break;
13968c2ecf20Sopenharmony_ci		}
13978c2ecf20Sopenharmony_ci
13988c2ecf20Sopenharmony_ci		if (priv->mux_select[MUX_HP_L] == HP_MUX_HP)
13998c2ecf20Sopenharmony_ci			mtk_hp_disable(priv);
14008c2ecf20Sopenharmony_ci		else if (priv->mux_select[MUX_HP_L] == HP_MUX_HPSPK)
14018c2ecf20Sopenharmony_ci			mtk_hp_spk_disable(priv);
14028c2ecf20Sopenharmony_ci
14038c2ecf20Sopenharmony_ci		priv->mux_select[MUX_HP_L] = mux;
14048c2ecf20Sopenharmony_ci		break;
14058c2ecf20Sopenharmony_ci	default:
14068c2ecf20Sopenharmony_ci		break;
14078c2ecf20Sopenharmony_ci	}
14088c2ecf20Sopenharmony_ci
14098c2ecf20Sopenharmony_ci	return 0;
14108c2ecf20Sopenharmony_ci}
14118c2ecf20Sopenharmony_ci
14128c2ecf20Sopenharmony_cistatic int mt_rcv_event(struct snd_soc_dapm_widget *w,
14138c2ecf20Sopenharmony_ci			struct snd_kcontrol *kcontrol,
14148c2ecf20Sopenharmony_ci			int event)
14158c2ecf20Sopenharmony_ci{
14168c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
14178c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
14188c2ecf20Sopenharmony_ci
14198c2ecf20Sopenharmony_ci	dev_info(priv->dev, "%s(), event 0x%x, mux %u\n",
14208c2ecf20Sopenharmony_ci		 __func__,
14218c2ecf20Sopenharmony_ci		 event,
14228c2ecf20Sopenharmony_ci		 dapm_kcontrol_get_value(w->kcontrols[0]));
14238c2ecf20Sopenharmony_ci
14248c2ecf20Sopenharmony_ci	switch (event) {
14258c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
14268c2ecf20Sopenharmony_ci		/* Reduce ESD resistance of AU_REFN */
14278c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON2, 0x4000);
14288c2ecf20Sopenharmony_ci
14298c2ecf20Sopenharmony_ci		/* Turn on DA_600K_NCP_VA18 */
14308c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON1, 0x0001);
14318c2ecf20Sopenharmony_ci		/* Set NCP clock as 604kHz // 26MHz/43 = 604KHz */
14328c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON2, 0x002c);
14338c2ecf20Sopenharmony_ci		/* Toggle RG_DIVCKS_CHG */
14348c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON0, 0x0001);
14358c2ecf20Sopenharmony_ci		/* Set NCP soft start mode as default mode: 100us */
14368c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON4, 0x0003);
14378c2ecf20Sopenharmony_ci		/* Enable NCP */
14388c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDNCP_CLKDIV_CON3, 0x0000);
14398c2ecf20Sopenharmony_ci		usleep_range(250, 270);
14408c2ecf20Sopenharmony_ci
14418c2ecf20Sopenharmony_ci		/* Enable cap-less LDOs (1.5V) */
14428c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON14,
14438c2ecf20Sopenharmony_ci				   0x1055, 0x1055);
14448c2ecf20Sopenharmony_ci		/* Enable NV regulator (-1.2V) */
14458c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON15, 0x0001);
14468c2ecf20Sopenharmony_ci		usleep_range(100, 120);
14478c2ecf20Sopenharmony_ci
14488c2ecf20Sopenharmony_ci		/* Disable AUD_ZCD */
14498c2ecf20Sopenharmony_ci		hp_zcd_disable(priv);
14508c2ecf20Sopenharmony_ci
14518c2ecf20Sopenharmony_ci		/* Disable handset short-circuit protection */
14528c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON6, 0x0010);
14538c2ecf20Sopenharmony_ci
14548c2ecf20Sopenharmony_ci		/* Enable IBIST */
14558c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON12, 0x0055);
14568c2ecf20Sopenharmony_ci		/* Set HP DR bias current optimization, 010: 6uA */
14578c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON11, 0x4900);
14588c2ecf20Sopenharmony_ci		/* Set HP & ZCD bias current optimization */
14598c2ecf20Sopenharmony_ci		/* 01: ZCD: 4uA, HP/HS/LO: 5uA */
14608c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON12, 0x0055);
14618c2ecf20Sopenharmony_ci		/* Set HS STB enhance circuits */
14628c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON6, 0x0090);
14638c2ecf20Sopenharmony_ci
14648c2ecf20Sopenharmony_ci		/* Disable HP main CMFB loop */
14658c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON9, 0x0000);
14668c2ecf20Sopenharmony_ci		/* Select CMFB resistor bulk to AC mode */
14678c2ecf20Sopenharmony_ci		/* Selec HS/LO cap size (6.5pF default) */
14688c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON10, 0x0000);
14698c2ecf20Sopenharmony_ci
14708c2ecf20Sopenharmony_ci		/* Enable HS driver bias circuits */
14718c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON6, 0x0092);
14728c2ecf20Sopenharmony_ci		/* Enable HS driver core circuits */
14738c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON6, 0x0093);
14748c2ecf20Sopenharmony_ci
14758c2ecf20Sopenharmony_ci		/* Enable AUD_CLK */
14768c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON13,
14778c2ecf20Sopenharmony_ci				   0x1, 0x1);
14788c2ecf20Sopenharmony_ci
14798c2ecf20Sopenharmony_ci		/* Enable Audio DAC  */
14808c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON0, 0x0009);
14818c2ecf20Sopenharmony_ci		/* Enable low-noise mode of DAC */
14828c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON9, 0x0001);
14838c2ecf20Sopenharmony_ci		/* Switch HS MUX to audio DAC */
14848c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON6, 0x009b);
14858c2ecf20Sopenharmony_ci		break;
14868c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMD:
14878c2ecf20Sopenharmony_ci		/* HS mux to open */
14888c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON6,
14898c2ecf20Sopenharmony_ci				   RG_AUDHSMUXINPUTSEL_VAUDP15_MASK_SFT,
14908c2ecf20Sopenharmony_ci				   RCV_MUX_OPEN);
14918c2ecf20Sopenharmony_ci
14928c2ecf20Sopenharmony_ci		/* Disable Audio DAC */
14938c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON0,
14948c2ecf20Sopenharmony_ci				   0x000f, 0x0000);
14958c2ecf20Sopenharmony_ci
14968c2ecf20Sopenharmony_ci		/* Disable AUD_CLK */
14978c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON13,
14988c2ecf20Sopenharmony_ci				   0x1, 0x0);
14998c2ecf20Sopenharmony_ci
15008c2ecf20Sopenharmony_ci		/* decrease HS gain to minimum gain step by step */
15018c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_ZCD_CON3, DL_GAIN_N_40DB);
15028c2ecf20Sopenharmony_ci
15038c2ecf20Sopenharmony_ci		/* Disable HS driver core circuits */
15048c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON6,
15058c2ecf20Sopenharmony_ci				   0x1, 0x0);
15068c2ecf20Sopenharmony_ci
15078c2ecf20Sopenharmony_ci		/* Disable HS driver bias circuits */
15088c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON6,
15098c2ecf20Sopenharmony_ci				   0x1 << 1, 0x0000);
15108c2ecf20Sopenharmony_ci
15118c2ecf20Sopenharmony_ci		/* Disable HP aux CMFB loop */
15128c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON9,
15138c2ecf20Sopenharmony_ci				   0xff << 8, 0x0);
15148c2ecf20Sopenharmony_ci
15158c2ecf20Sopenharmony_ci		/* Enable HP main CMFB Switch */
15168c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON9,
15178c2ecf20Sopenharmony_ci				   0xff << 8, 0x2 << 8);
15188c2ecf20Sopenharmony_ci
15198c2ecf20Sopenharmony_ci		/* Disable IBIST */
15208c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON12,
15218c2ecf20Sopenharmony_ci				   0x1 << 8, 0x1 << 8);
15228c2ecf20Sopenharmony_ci
15238c2ecf20Sopenharmony_ci		/* Disable NV regulator (-1.2V) */
15248c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON15,
15258c2ecf20Sopenharmony_ci				   0x1, 0x0);
15268c2ecf20Sopenharmony_ci		/* Disable cap-less LDOs (1.5V) */
15278c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON14,
15288c2ecf20Sopenharmony_ci				   0x1055, 0x0);
15298c2ecf20Sopenharmony_ci		/* Disable NCP */
15308c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDNCP_CLKDIV_CON3,
15318c2ecf20Sopenharmony_ci				   0x1, 0x1);
15328c2ecf20Sopenharmony_ci		break;
15338c2ecf20Sopenharmony_ci	default:
15348c2ecf20Sopenharmony_ci		break;
15358c2ecf20Sopenharmony_ci	}
15368c2ecf20Sopenharmony_ci
15378c2ecf20Sopenharmony_ci	return 0;
15388c2ecf20Sopenharmony_ci}
15398c2ecf20Sopenharmony_ci
15408c2ecf20Sopenharmony_cistatic int mt_aif_out_event(struct snd_soc_dapm_widget *w,
15418c2ecf20Sopenharmony_ci			    struct snd_kcontrol *kcontrol,
15428c2ecf20Sopenharmony_ci			    int event)
15438c2ecf20Sopenharmony_ci{
15448c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
15458c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
15468c2ecf20Sopenharmony_ci
15478c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event 0x%x, rate %d\n",
15488c2ecf20Sopenharmony_ci		__func__, event, priv->ul_rate);
15498c2ecf20Sopenharmony_ci
15508c2ecf20Sopenharmony_ci	switch (event) {
15518c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
15528c2ecf20Sopenharmony_ci		capture_gpio_set(priv);
15538c2ecf20Sopenharmony_ci		break;
15548c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
15558c2ecf20Sopenharmony_ci		capture_gpio_reset(priv);
15568c2ecf20Sopenharmony_ci		break;
15578c2ecf20Sopenharmony_ci	default:
15588c2ecf20Sopenharmony_ci		break;
15598c2ecf20Sopenharmony_ci	}
15608c2ecf20Sopenharmony_ci
15618c2ecf20Sopenharmony_ci	return 0;
15628c2ecf20Sopenharmony_ci}
15638c2ecf20Sopenharmony_ci
15648c2ecf20Sopenharmony_cistatic int mt_adc_supply_event(struct snd_soc_dapm_widget *w,
15658c2ecf20Sopenharmony_ci			       struct snd_kcontrol *kcontrol,
15668c2ecf20Sopenharmony_ci			       int event)
15678c2ecf20Sopenharmony_ci{
15688c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
15698c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
15708c2ecf20Sopenharmony_ci
15718c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event 0x%x\n",
15728c2ecf20Sopenharmony_ci		__func__, event);
15738c2ecf20Sopenharmony_ci
15748c2ecf20Sopenharmony_ci	switch (event) {
15758c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
15768c2ecf20Sopenharmony_ci		/* Enable audio ADC CLKGEN  */
15778c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON13,
15788c2ecf20Sopenharmony_ci				   0x1 << 5, 0x1 << 5);
15798c2ecf20Sopenharmony_ci		/* ADC CLK from CLKGEN (13MHz) */
15808c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDENC_ANA_CON3,
15818c2ecf20Sopenharmony_ci			     0x0000);
15828c2ecf20Sopenharmony_ci		/* Enable  LCLDO_ENC 1P8V */
15838c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON14,
15848c2ecf20Sopenharmony_ci				   0x2500, 0x0100);
15858c2ecf20Sopenharmony_ci		/* LCLDO_ENC remote sense */
15868c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON14,
15878c2ecf20Sopenharmony_ci				   0x2500, 0x2500);
15888c2ecf20Sopenharmony_ci		break;
15898c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
15908c2ecf20Sopenharmony_ci		/* LCLDO_ENC remote sense off */
15918c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON14,
15928c2ecf20Sopenharmony_ci				   0x2500, 0x0100);
15938c2ecf20Sopenharmony_ci		/* disable LCLDO_ENC 1P8V */
15948c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON14,
15958c2ecf20Sopenharmony_ci				   0x2500, 0x0000);
15968c2ecf20Sopenharmony_ci
15978c2ecf20Sopenharmony_ci		/* ADC CLK from CLKGEN (13MHz) */
15988c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AUDENC_ANA_CON3, 0x0000);
15998c2ecf20Sopenharmony_ci		/* disable audio ADC CLKGEN  */
16008c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON13,
16018c2ecf20Sopenharmony_ci				   0x1 << 5, 0x0 << 5);
16028c2ecf20Sopenharmony_ci		break;
16038c2ecf20Sopenharmony_ci	default:
16048c2ecf20Sopenharmony_ci		break;
16058c2ecf20Sopenharmony_ci	}
16068c2ecf20Sopenharmony_ci
16078c2ecf20Sopenharmony_ci	return 0;
16088c2ecf20Sopenharmony_ci}
16098c2ecf20Sopenharmony_ci
16108c2ecf20Sopenharmony_cistatic int mt6358_amic_enable(struct mt6358_priv *priv)
16118c2ecf20Sopenharmony_ci{
16128c2ecf20Sopenharmony_ci	unsigned int mic_type = priv->mux_select[MUX_MIC_TYPE];
16138c2ecf20Sopenharmony_ci	unsigned int mux_pga_l = priv->mux_select[MUX_PGA_L];
16148c2ecf20Sopenharmony_ci	unsigned int mux_pga_r = priv->mux_select[MUX_PGA_R];
16158c2ecf20Sopenharmony_ci
16168c2ecf20Sopenharmony_ci	dev_info(priv->dev, "%s(), mux, mic %u, pga l %u, pga r %u\n",
16178c2ecf20Sopenharmony_ci		 __func__, mic_type, mux_pga_l, mux_pga_r);
16188c2ecf20Sopenharmony_ci
16198c2ecf20Sopenharmony_ci	if (IS_DCC_BASE(mic_type)) {
16208c2ecf20Sopenharmony_ci		/* DCC 50k CLK (from 26M) */
16218c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFE_DCCLK_CFG0, 0x2062);
16228c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFE_DCCLK_CFG0, 0x2062);
16238c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFE_DCCLK_CFG0, 0x2060);
16248c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFE_DCCLK_CFG0, 0x2061);
16258c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFE_DCCLK_CFG1, 0x0100);
16268c2ecf20Sopenharmony_ci	}
16278c2ecf20Sopenharmony_ci
16288c2ecf20Sopenharmony_ci	/* mic bias 0 */
16298c2ecf20Sopenharmony_ci	if (mux_pga_l == PGA_MUX_AIN0 || mux_pga_l == PGA_MUX_AIN2 ||
16308c2ecf20Sopenharmony_ci	    mux_pga_r == PGA_MUX_AIN0 || mux_pga_r == PGA_MUX_AIN2) {
16318c2ecf20Sopenharmony_ci		switch (mic_type) {
16328c2ecf20Sopenharmony_ci		case MIC_TYPE_MUX_DCC_ECM_DIFF:
16338c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON9,
16348c2ecf20Sopenharmony_ci					   0xff00, 0x7700);
16358c2ecf20Sopenharmony_ci			break;
16368c2ecf20Sopenharmony_ci		case MIC_TYPE_MUX_DCC_ECM_SINGLE:
16378c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON9,
16388c2ecf20Sopenharmony_ci					   0xff00, 0x1100);
16398c2ecf20Sopenharmony_ci			break;
16408c2ecf20Sopenharmony_ci		default:
16418c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON9,
16428c2ecf20Sopenharmony_ci					   0xff00, 0x0000);
16438c2ecf20Sopenharmony_ci			break;
16448c2ecf20Sopenharmony_ci		}
16458c2ecf20Sopenharmony_ci		/* Enable MICBIAS0, MISBIAS0 = 1P9V */
16468c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON9,
16478c2ecf20Sopenharmony_ci				   0xff, 0x21);
16488c2ecf20Sopenharmony_ci	}
16498c2ecf20Sopenharmony_ci
16508c2ecf20Sopenharmony_ci	/* mic bias 1 */
16518c2ecf20Sopenharmony_ci	if (mux_pga_l == PGA_MUX_AIN1 || mux_pga_r == PGA_MUX_AIN1) {
16528c2ecf20Sopenharmony_ci		/* Enable MICBIAS1, MISBIAS1 = 2P6V */
16538c2ecf20Sopenharmony_ci		if (mic_type == MIC_TYPE_MUX_DCC_ECM_SINGLE)
16548c2ecf20Sopenharmony_ci			regmap_write(priv->regmap,
16558c2ecf20Sopenharmony_ci				     MT6358_AUDENC_ANA_CON10, 0x0161);
16568c2ecf20Sopenharmony_ci		else
16578c2ecf20Sopenharmony_ci			regmap_write(priv->regmap,
16588c2ecf20Sopenharmony_ci				     MT6358_AUDENC_ANA_CON10, 0x0061);
16598c2ecf20Sopenharmony_ci	}
16608c2ecf20Sopenharmony_ci
16618c2ecf20Sopenharmony_ci	if (IS_DCC_BASE(mic_type)) {
16628c2ecf20Sopenharmony_ci		/* Audio L/R preamplifier DCC precharge */
16638c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
16648c2ecf20Sopenharmony_ci				   0xf8ff, 0x0004);
16658c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
16668c2ecf20Sopenharmony_ci				   0xf8ff, 0x0004);
16678c2ecf20Sopenharmony_ci	} else {
16688c2ecf20Sopenharmony_ci		/* reset reg */
16698c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
16708c2ecf20Sopenharmony_ci				   0xf8ff, 0x0000);
16718c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
16728c2ecf20Sopenharmony_ci				   0xf8ff, 0x0000);
16738c2ecf20Sopenharmony_ci	}
16748c2ecf20Sopenharmony_ci
16758c2ecf20Sopenharmony_ci	if (mux_pga_l != PGA_MUX_NONE) {
16768c2ecf20Sopenharmony_ci		/* L preamplifier input sel */
16778c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
16788c2ecf20Sopenharmony_ci				   RG_AUDPREAMPLINPUTSEL_MASK_SFT,
16798c2ecf20Sopenharmony_ci				   mux_pga_l << RG_AUDPREAMPLINPUTSEL_SFT);
16808c2ecf20Sopenharmony_ci
16818c2ecf20Sopenharmony_ci		/* L preamplifier enable */
16828c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
16838c2ecf20Sopenharmony_ci				   RG_AUDPREAMPLON_MASK_SFT,
16848c2ecf20Sopenharmony_ci				   0x1 << RG_AUDPREAMPLON_SFT);
16858c2ecf20Sopenharmony_ci
16868c2ecf20Sopenharmony_ci		if (IS_DCC_BASE(mic_type)) {
16878c2ecf20Sopenharmony_ci			/* L preamplifier DCCEN */
16888c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
16898c2ecf20Sopenharmony_ci					   RG_AUDPREAMPLDCCEN_MASK_SFT,
16908c2ecf20Sopenharmony_ci					   0x1 << RG_AUDPREAMPLDCCEN_SFT);
16918c2ecf20Sopenharmony_ci		}
16928c2ecf20Sopenharmony_ci
16938c2ecf20Sopenharmony_ci		/* L ADC input sel : L PGA. Enable audio L ADC */
16948c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
16958c2ecf20Sopenharmony_ci				   RG_AUDADCLINPUTSEL_MASK_SFT,
16968c2ecf20Sopenharmony_ci				   ADC_MUX_PREAMPLIFIER <<
16978c2ecf20Sopenharmony_ci				   RG_AUDADCLINPUTSEL_SFT);
16988c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
16998c2ecf20Sopenharmony_ci				   RG_AUDADCLPWRUP_MASK_SFT,
17008c2ecf20Sopenharmony_ci				   0x1 << RG_AUDADCLPWRUP_SFT);
17018c2ecf20Sopenharmony_ci	}
17028c2ecf20Sopenharmony_ci
17038c2ecf20Sopenharmony_ci	if (mux_pga_r != PGA_MUX_NONE) {
17048c2ecf20Sopenharmony_ci		/* R preamplifier input sel */
17058c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
17068c2ecf20Sopenharmony_ci				   RG_AUDPREAMPRINPUTSEL_MASK_SFT,
17078c2ecf20Sopenharmony_ci				   mux_pga_r << RG_AUDPREAMPRINPUTSEL_SFT);
17088c2ecf20Sopenharmony_ci
17098c2ecf20Sopenharmony_ci		/* R preamplifier enable */
17108c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
17118c2ecf20Sopenharmony_ci				   RG_AUDPREAMPRON_MASK_SFT,
17128c2ecf20Sopenharmony_ci				   0x1 << RG_AUDPREAMPRON_SFT);
17138c2ecf20Sopenharmony_ci
17148c2ecf20Sopenharmony_ci		if (IS_DCC_BASE(mic_type)) {
17158c2ecf20Sopenharmony_ci			/* R preamplifier DCCEN */
17168c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
17178c2ecf20Sopenharmony_ci					   RG_AUDPREAMPRDCCEN_MASK_SFT,
17188c2ecf20Sopenharmony_ci					   0x1 << RG_AUDPREAMPRDCCEN_SFT);
17198c2ecf20Sopenharmony_ci		}
17208c2ecf20Sopenharmony_ci
17218c2ecf20Sopenharmony_ci		/* R ADC input sel : R PGA. Enable audio R ADC */
17228c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
17238c2ecf20Sopenharmony_ci				   RG_AUDADCRINPUTSEL_MASK_SFT,
17248c2ecf20Sopenharmony_ci				   ADC_MUX_PREAMPLIFIER <<
17258c2ecf20Sopenharmony_ci				   RG_AUDADCRINPUTSEL_SFT);
17268c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
17278c2ecf20Sopenharmony_ci				   RG_AUDADCRPWRUP_MASK_SFT,
17288c2ecf20Sopenharmony_ci				   0x1 << RG_AUDADCRPWRUP_SFT);
17298c2ecf20Sopenharmony_ci	}
17308c2ecf20Sopenharmony_ci
17318c2ecf20Sopenharmony_ci	if (IS_DCC_BASE(mic_type)) {
17328c2ecf20Sopenharmony_ci		usleep_range(100, 150);
17338c2ecf20Sopenharmony_ci		/* Audio L preamplifier DCC precharge off */
17348c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
17358c2ecf20Sopenharmony_ci				   RG_AUDPREAMPLDCPRECHARGE_MASK_SFT, 0x0);
17368c2ecf20Sopenharmony_ci		/* Audio R preamplifier DCC precharge off */
17378c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
17388c2ecf20Sopenharmony_ci				   RG_AUDPREAMPRDCPRECHARGE_MASK_SFT, 0x0);
17398c2ecf20Sopenharmony_ci
17408c2ecf20Sopenharmony_ci		/* Short body to ground in PGA */
17418c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON3,
17428c2ecf20Sopenharmony_ci				   0x1 << 12, 0x0);
17438c2ecf20Sopenharmony_ci	}
17448c2ecf20Sopenharmony_ci
17458c2ecf20Sopenharmony_ci	/* here to set digital part */
17468c2ecf20Sopenharmony_ci	mt6358_mtkaif_tx_enable(priv);
17478c2ecf20Sopenharmony_ci
17488c2ecf20Sopenharmony_ci	/* UL dmic setting off */
17498c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AFE_UL_SRC_CON0_H, 0x0000);
17508c2ecf20Sopenharmony_ci
17518c2ecf20Sopenharmony_ci	/* UL turn on */
17528c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AFE_UL_SRC_CON0_L, 0x0001);
17538c2ecf20Sopenharmony_ci
17548c2ecf20Sopenharmony_ci	return 0;
17558c2ecf20Sopenharmony_ci}
17568c2ecf20Sopenharmony_ci
17578c2ecf20Sopenharmony_cistatic void mt6358_amic_disable(struct mt6358_priv *priv)
17588c2ecf20Sopenharmony_ci{
17598c2ecf20Sopenharmony_ci	unsigned int mic_type = priv->mux_select[MUX_MIC_TYPE];
17608c2ecf20Sopenharmony_ci	unsigned int mux_pga_l = priv->mux_select[MUX_PGA_L];
17618c2ecf20Sopenharmony_ci	unsigned int mux_pga_r = priv->mux_select[MUX_PGA_R];
17628c2ecf20Sopenharmony_ci
17638c2ecf20Sopenharmony_ci	dev_info(priv->dev, "%s(), mux, mic %u, pga l %u, pga r %u\n",
17648c2ecf20Sopenharmony_ci		 __func__, mic_type, mux_pga_l, mux_pga_r);
17658c2ecf20Sopenharmony_ci
17668c2ecf20Sopenharmony_ci	/* UL turn off */
17678c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_UL_SRC_CON0_L,
17688c2ecf20Sopenharmony_ci			   0x0001, 0x0000);
17698c2ecf20Sopenharmony_ci
17708c2ecf20Sopenharmony_ci	/* disable aud_pad TX fifos */
17718c2ecf20Sopenharmony_ci	mt6358_mtkaif_tx_disable(priv);
17728c2ecf20Sopenharmony_ci
17738c2ecf20Sopenharmony_ci	/* L ADC input sel : off, disable L ADC */
17748c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
17758c2ecf20Sopenharmony_ci			   0xf000, 0x0000);
17768c2ecf20Sopenharmony_ci	/* L preamplifier DCCEN */
17778c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
17788c2ecf20Sopenharmony_ci			   0x1 << 1, 0x0);
17798c2ecf20Sopenharmony_ci	/* L preamplifier input sel : off, L PGA 0 dB gain */
17808c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
17818c2ecf20Sopenharmony_ci			   0xfffb, 0x0000);
17828c2ecf20Sopenharmony_ci
17838c2ecf20Sopenharmony_ci	/* disable L preamplifier DCC precharge */
17848c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
17858c2ecf20Sopenharmony_ci			   0x1 << 2, 0x0);
17868c2ecf20Sopenharmony_ci
17878c2ecf20Sopenharmony_ci	/* R ADC input sel : off, disable R ADC */
17888c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
17898c2ecf20Sopenharmony_ci			   0xf000, 0x0000);
17908c2ecf20Sopenharmony_ci	/* R preamplifier DCCEN */
17918c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
17928c2ecf20Sopenharmony_ci			   0x1 << 1, 0x0);
17938c2ecf20Sopenharmony_ci	/* R preamplifier input sel : off, R PGA 0 dB gain */
17948c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
17958c2ecf20Sopenharmony_ci			   0x0ffb, 0x0000);
17968c2ecf20Sopenharmony_ci
17978c2ecf20Sopenharmony_ci	/* disable R preamplifier DCC precharge */
17988c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
17998c2ecf20Sopenharmony_ci			   0x1 << 2, 0x0);
18008c2ecf20Sopenharmony_ci
18018c2ecf20Sopenharmony_ci	/* mic bias */
18028c2ecf20Sopenharmony_ci	/* Disable MICBIAS0, MISBIAS0 = 1P7V */
18038c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDENC_ANA_CON9, 0x0000);
18048c2ecf20Sopenharmony_ci
18058c2ecf20Sopenharmony_ci	/* Disable MICBIAS1 */
18068c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON10,
18078c2ecf20Sopenharmony_ci			   0x0001, 0x0000);
18088c2ecf20Sopenharmony_ci
18098c2ecf20Sopenharmony_ci	if (IS_DCC_BASE(mic_type)) {
18108c2ecf20Sopenharmony_ci		/* dcclk_gen_on=1'b0 */
18118c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFE_DCCLK_CFG0, 0x2060);
18128c2ecf20Sopenharmony_ci		/* dcclk_pdn=1'b1 */
18138c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFE_DCCLK_CFG0, 0x2062);
18148c2ecf20Sopenharmony_ci		/* dcclk_ref_ck_sel=2'b00 */
18158c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFE_DCCLK_CFG0, 0x2062);
18168c2ecf20Sopenharmony_ci		/* dcclk_div=11'b00100000011 */
18178c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFE_DCCLK_CFG0, 0x2062);
18188c2ecf20Sopenharmony_ci	}
18198c2ecf20Sopenharmony_ci}
18208c2ecf20Sopenharmony_ci
18218c2ecf20Sopenharmony_cistatic int mt6358_dmic_enable(struct mt6358_priv *priv)
18228c2ecf20Sopenharmony_ci{
18238c2ecf20Sopenharmony_ci	dev_info(priv->dev, "%s()\n", __func__);
18248c2ecf20Sopenharmony_ci
18258c2ecf20Sopenharmony_ci	/* mic bias */
18268c2ecf20Sopenharmony_ci	/* Enable MICBIAS0, MISBIAS0 = 1P9V */
18278c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDENC_ANA_CON9, 0x0021);
18288c2ecf20Sopenharmony_ci
18298c2ecf20Sopenharmony_ci	/* RG_BANDGAPGEN=1'b0 */
18308c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON10,
18318c2ecf20Sopenharmony_ci			   0x1 << 12, 0x0);
18328c2ecf20Sopenharmony_ci
18338c2ecf20Sopenharmony_ci	/* DMIC enable */
18348c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDENC_ANA_CON8, 0x0005);
18358c2ecf20Sopenharmony_ci
18368c2ecf20Sopenharmony_ci	/* here to set digital part */
18378c2ecf20Sopenharmony_ci	mt6358_mtkaif_tx_enable(priv);
18388c2ecf20Sopenharmony_ci
18398c2ecf20Sopenharmony_ci	/* UL dmic setting */
18408c2ecf20Sopenharmony_ci	if (priv->dmic_one_wire_mode)
18418c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFE_UL_SRC_CON0_H, 0x0400);
18428c2ecf20Sopenharmony_ci	else
18438c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, MT6358_AFE_UL_SRC_CON0_H, 0x0080);
18448c2ecf20Sopenharmony_ci
18458c2ecf20Sopenharmony_ci	/* UL turn on */
18468c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AFE_UL_SRC_CON0_L, 0x0003);
18478c2ecf20Sopenharmony_ci
18488c2ecf20Sopenharmony_ci	/* Prevent pop noise form dmic hw */
18498c2ecf20Sopenharmony_ci	msleep(100);
18508c2ecf20Sopenharmony_ci
18518c2ecf20Sopenharmony_ci	return 0;
18528c2ecf20Sopenharmony_ci}
18538c2ecf20Sopenharmony_ci
18548c2ecf20Sopenharmony_cistatic void mt6358_dmic_disable(struct mt6358_priv *priv)
18558c2ecf20Sopenharmony_ci{
18568c2ecf20Sopenharmony_ci	dev_info(priv->dev, "%s()\n", __func__);
18578c2ecf20Sopenharmony_ci
18588c2ecf20Sopenharmony_ci	/* UL turn off */
18598c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AFE_UL_SRC_CON0_L,
18608c2ecf20Sopenharmony_ci			   0x0003, 0x0000);
18618c2ecf20Sopenharmony_ci
18628c2ecf20Sopenharmony_ci	/* disable aud_pad TX fifos */
18638c2ecf20Sopenharmony_ci	mt6358_mtkaif_tx_disable(priv);
18648c2ecf20Sopenharmony_ci
18658c2ecf20Sopenharmony_ci	/* DMIC disable */
18668c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDENC_ANA_CON8, 0x0000);
18678c2ecf20Sopenharmony_ci
18688c2ecf20Sopenharmony_ci	/* mic bias */
18698c2ecf20Sopenharmony_ci	/* MISBIAS0 = 1P7V */
18708c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDENC_ANA_CON9, 0x0001);
18718c2ecf20Sopenharmony_ci
18728c2ecf20Sopenharmony_ci	/* RG_BANDGAPGEN=1'b0 */
18738c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON10,
18748c2ecf20Sopenharmony_ci			   0x1 << 12, 0x0);
18758c2ecf20Sopenharmony_ci
18768c2ecf20Sopenharmony_ci	/* MICBIA0 disable */
18778c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_AUDENC_ANA_CON9, 0x0000);
18788c2ecf20Sopenharmony_ci}
18798c2ecf20Sopenharmony_ci
18808c2ecf20Sopenharmony_cistatic void mt6358_restore_pga(struct mt6358_priv *priv)
18818c2ecf20Sopenharmony_ci{
18828c2ecf20Sopenharmony_ci	unsigned int gain_l, gain_r;
18838c2ecf20Sopenharmony_ci
18848c2ecf20Sopenharmony_ci	gain_l = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1];
18858c2ecf20Sopenharmony_ci	gain_r = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2];
18868c2ecf20Sopenharmony_ci
18878c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0,
18888c2ecf20Sopenharmony_ci			   RG_AUDPREAMPLGAIN_MASK_SFT,
18898c2ecf20Sopenharmony_ci			   gain_l << RG_AUDPREAMPLGAIN_SFT);
18908c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1,
18918c2ecf20Sopenharmony_ci			   RG_AUDPREAMPRGAIN_MASK_SFT,
18928c2ecf20Sopenharmony_ci			   gain_r << RG_AUDPREAMPRGAIN_SFT);
18938c2ecf20Sopenharmony_ci}
18948c2ecf20Sopenharmony_ci
18958c2ecf20Sopenharmony_cistatic int mt_mic_type_event(struct snd_soc_dapm_widget *w,
18968c2ecf20Sopenharmony_ci			     struct snd_kcontrol *kcontrol,
18978c2ecf20Sopenharmony_ci			     int event)
18988c2ecf20Sopenharmony_ci{
18998c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
19008c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
19018c2ecf20Sopenharmony_ci	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
19028c2ecf20Sopenharmony_ci
19038c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event 0x%x, mux %u\n",
19048c2ecf20Sopenharmony_ci		__func__, event, mux);
19058c2ecf20Sopenharmony_ci
19068c2ecf20Sopenharmony_ci	switch (event) {
19078c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_WILL_PMU:
19088c2ecf20Sopenharmony_ci		priv->mux_select[MUX_MIC_TYPE] = mux;
19098c2ecf20Sopenharmony_ci		break;
19108c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
19118c2ecf20Sopenharmony_ci		switch (mux) {
19128c2ecf20Sopenharmony_ci		case MIC_TYPE_MUX_DMIC:
19138c2ecf20Sopenharmony_ci			mt6358_dmic_enable(priv);
19148c2ecf20Sopenharmony_ci			break;
19158c2ecf20Sopenharmony_ci		default:
19168c2ecf20Sopenharmony_ci			mt6358_amic_enable(priv);
19178c2ecf20Sopenharmony_ci			break;
19188c2ecf20Sopenharmony_ci		}
19198c2ecf20Sopenharmony_ci		mt6358_restore_pga(priv);
19208c2ecf20Sopenharmony_ci
19218c2ecf20Sopenharmony_ci		break;
19228c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
19238c2ecf20Sopenharmony_ci		switch (priv->mux_select[MUX_MIC_TYPE]) {
19248c2ecf20Sopenharmony_ci		case MIC_TYPE_MUX_DMIC:
19258c2ecf20Sopenharmony_ci			mt6358_dmic_disable(priv);
19268c2ecf20Sopenharmony_ci			break;
19278c2ecf20Sopenharmony_ci		default:
19288c2ecf20Sopenharmony_ci			mt6358_amic_disable(priv);
19298c2ecf20Sopenharmony_ci			break;
19308c2ecf20Sopenharmony_ci		}
19318c2ecf20Sopenharmony_ci
19328c2ecf20Sopenharmony_ci		priv->mux_select[MUX_MIC_TYPE] = mux;
19338c2ecf20Sopenharmony_ci		break;
19348c2ecf20Sopenharmony_ci	default:
19358c2ecf20Sopenharmony_ci		break;
19368c2ecf20Sopenharmony_ci	}
19378c2ecf20Sopenharmony_ci
19388c2ecf20Sopenharmony_ci	return 0;
19398c2ecf20Sopenharmony_ci}
19408c2ecf20Sopenharmony_ci
19418c2ecf20Sopenharmony_cistatic int mt_adc_l_event(struct snd_soc_dapm_widget *w,
19428c2ecf20Sopenharmony_ci			  struct snd_kcontrol *kcontrol,
19438c2ecf20Sopenharmony_ci			  int event)
19448c2ecf20Sopenharmony_ci{
19458c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
19468c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
19478c2ecf20Sopenharmony_ci	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
19488c2ecf20Sopenharmony_ci
19498c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event = 0x%x, mux %u\n",
19508c2ecf20Sopenharmony_ci		__func__, event, mux);
19518c2ecf20Sopenharmony_ci
19528c2ecf20Sopenharmony_ci	priv->mux_select[MUX_ADC_L] = mux;
19538c2ecf20Sopenharmony_ci
19548c2ecf20Sopenharmony_ci	return 0;
19558c2ecf20Sopenharmony_ci}
19568c2ecf20Sopenharmony_ci
19578c2ecf20Sopenharmony_cistatic int mt_adc_r_event(struct snd_soc_dapm_widget *w,
19588c2ecf20Sopenharmony_ci			  struct snd_kcontrol *kcontrol,
19598c2ecf20Sopenharmony_ci			  int event)
19608c2ecf20Sopenharmony_ci{
19618c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
19628c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
19638c2ecf20Sopenharmony_ci	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
19648c2ecf20Sopenharmony_ci
19658c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event = 0x%x, mux %u\n",
19668c2ecf20Sopenharmony_ci		__func__, event, mux);
19678c2ecf20Sopenharmony_ci
19688c2ecf20Sopenharmony_ci	priv->mux_select[MUX_ADC_R] = mux;
19698c2ecf20Sopenharmony_ci
19708c2ecf20Sopenharmony_ci	return 0;
19718c2ecf20Sopenharmony_ci}
19728c2ecf20Sopenharmony_ci
19738c2ecf20Sopenharmony_cistatic int mt_pga_left_event(struct snd_soc_dapm_widget *w,
19748c2ecf20Sopenharmony_ci			     struct snd_kcontrol *kcontrol,
19758c2ecf20Sopenharmony_ci			     int event)
19768c2ecf20Sopenharmony_ci{
19778c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
19788c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
19798c2ecf20Sopenharmony_ci	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
19808c2ecf20Sopenharmony_ci
19818c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event = 0x%x, mux %u\n",
19828c2ecf20Sopenharmony_ci		__func__, event, mux);
19838c2ecf20Sopenharmony_ci
19848c2ecf20Sopenharmony_ci	priv->mux_select[MUX_PGA_L] = mux;
19858c2ecf20Sopenharmony_ci
19868c2ecf20Sopenharmony_ci	return 0;
19878c2ecf20Sopenharmony_ci}
19888c2ecf20Sopenharmony_ci
19898c2ecf20Sopenharmony_cistatic int mt_pga_right_event(struct snd_soc_dapm_widget *w,
19908c2ecf20Sopenharmony_ci			      struct snd_kcontrol *kcontrol,
19918c2ecf20Sopenharmony_ci			      int event)
19928c2ecf20Sopenharmony_ci{
19938c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
19948c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
19958c2ecf20Sopenharmony_ci	unsigned int mux = dapm_kcontrol_get_value(w->kcontrols[0]);
19968c2ecf20Sopenharmony_ci
19978c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event = 0x%x, mux %u\n",
19988c2ecf20Sopenharmony_ci		__func__, event, mux);
19998c2ecf20Sopenharmony_ci
20008c2ecf20Sopenharmony_ci	priv->mux_select[MUX_PGA_R] = mux;
20018c2ecf20Sopenharmony_ci
20028c2ecf20Sopenharmony_ci	return 0;
20038c2ecf20Sopenharmony_ci}
20048c2ecf20Sopenharmony_ci
20058c2ecf20Sopenharmony_cistatic int mt_delay_250_event(struct snd_soc_dapm_widget *w,
20068c2ecf20Sopenharmony_ci			      struct snd_kcontrol *kcontrol,
20078c2ecf20Sopenharmony_ci			      int event)
20088c2ecf20Sopenharmony_ci{
20098c2ecf20Sopenharmony_ci	switch (event) {
20108c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
20118c2ecf20Sopenharmony_ci		usleep_range(250, 270);
20128c2ecf20Sopenharmony_ci		break;
20138c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMD:
20148c2ecf20Sopenharmony_ci		usleep_range(250, 270);
20158c2ecf20Sopenharmony_ci		break;
20168c2ecf20Sopenharmony_ci	default:
20178c2ecf20Sopenharmony_ci		break;
20188c2ecf20Sopenharmony_ci	}
20198c2ecf20Sopenharmony_ci
20208c2ecf20Sopenharmony_ci	return 0;
20218c2ecf20Sopenharmony_ci}
20228c2ecf20Sopenharmony_ci
20238c2ecf20Sopenharmony_ci/* DAPM Widgets */
20248c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget mt6358_dapm_widgets[] = {
20258c2ecf20Sopenharmony_ci	/* Global Supply*/
20268c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("CLK_BUF", SUPPLY_SEQ_CLK_BUF,
20278c2ecf20Sopenharmony_ci			      MT6358_DCXO_CW14,
20288c2ecf20Sopenharmony_ci			      RG_XO_AUDIO_EN_M_SFT, 0, NULL, 0),
20298c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AUDGLB", SUPPLY_SEQ_AUD_GLB,
20308c2ecf20Sopenharmony_ci			      MT6358_AUDDEC_ANA_CON13,
20318c2ecf20Sopenharmony_ci			      RG_AUDGLB_PWRDN_VA28_SFT, 1, NULL, 0),
20328c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("CLKSQ Audio", SUPPLY_SEQ_CLKSQ,
20338c2ecf20Sopenharmony_ci			      MT6358_AUDENC_ANA_CON6,
20348c2ecf20Sopenharmony_ci			      RG_CLKSQ_EN_SFT, 0,
20358c2ecf20Sopenharmony_ci			      mt_clksq_event,
20368c2ecf20Sopenharmony_ci			      SND_SOC_DAPM_PRE_PMU),
20378c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AUDNCP_CK", SUPPLY_SEQ_TOP_CK,
20388c2ecf20Sopenharmony_ci			      MT6358_AUD_TOP_CKPDN_CON0,
20398c2ecf20Sopenharmony_ci			      RG_AUDNCP_CK_PDN_SFT, 1, NULL, 0),
20408c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("ZCD13M_CK", SUPPLY_SEQ_TOP_CK,
20418c2ecf20Sopenharmony_ci			      MT6358_AUD_TOP_CKPDN_CON0,
20428c2ecf20Sopenharmony_ci			      RG_ZCD13M_CK_PDN_SFT, 1, NULL, 0),
20438c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AUD_CK", SUPPLY_SEQ_TOP_CK_LAST,
20448c2ecf20Sopenharmony_ci			      MT6358_AUD_TOP_CKPDN_CON0,
20458c2ecf20Sopenharmony_ci			      RG_AUD_CK_PDN_SFT, 1,
20468c2ecf20Sopenharmony_ci			      mt_delay_250_event,
20478c2ecf20Sopenharmony_ci			      SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
20488c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AUDIF_CK", SUPPLY_SEQ_TOP_CK,
20498c2ecf20Sopenharmony_ci			      MT6358_AUD_TOP_CKPDN_CON0,
20508c2ecf20Sopenharmony_ci			      RG_AUDIF_CK_PDN_SFT, 1, NULL, 0),
20518c2ecf20Sopenharmony_ci
20528c2ecf20Sopenharmony_ci	/* Digital Clock */
20538c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_AFE_CTL", SUPPLY_SEQ_AUD_TOP_LAST,
20548c2ecf20Sopenharmony_ci			      MT6358_AUDIO_TOP_CON0,
20558c2ecf20Sopenharmony_ci			      PDN_AFE_CTL_SFT, 1,
20568c2ecf20Sopenharmony_ci			      mt_delay_250_event,
20578c2ecf20Sopenharmony_ci			      SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
20588c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_DAC_CTL", SUPPLY_SEQ_AUD_TOP,
20598c2ecf20Sopenharmony_ci			      MT6358_AUDIO_TOP_CON0,
20608c2ecf20Sopenharmony_ci			      PDN_DAC_CTL_SFT, 1, NULL, 0),
20618c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_ADC_CTL", SUPPLY_SEQ_AUD_TOP,
20628c2ecf20Sopenharmony_ci			      MT6358_AUDIO_TOP_CON0,
20638c2ecf20Sopenharmony_ci			      PDN_ADC_CTL_SFT, 1, NULL, 0),
20648c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_I2S_DL", SUPPLY_SEQ_AUD_TOP,
20658c2ecf20Sopenharmony_ci			      MT6358_AUDIO_TOP_CON0,
20668c2ecf20Sopenharmony_ci			      PDN_I2S_DL_CTL_SFT, 1, NULL, 0),
20678c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PWR_CLK", SUPPLY_SEQ_AUD_TOP,
20688c2ecf20Sopenharmony_ci			      MT6358_AUDIO_TOP_CON0,
20698c2ecf20Sopenharmony_ci			      PWR_CLK_DIS_CTL_SFT, 1, NULL, 0),
20708c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PDN_AFE_TESTMODEL", SUPPLY_SEQ_AUD_TOP,
20718c2ecf20Sopenharmony_ci			      MT6358_AUDIO_TOP_CON0,
20728c2ecf20Sopenharmony_ci			      PDN_AFE_TESTMODEL_CTL_SFT, 1, NULL, 0),
20738c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AUDIO_TOP_PDN_RESERVED", SUPPLY_SEQ_AUD_TOP,
20748c2ecf20Sopenharmony_ci			      MT6358_AUDIO_TOP_CON0,
20758c2ecf20Sopenharmony_ci			      PDN_RESERVED_SFT, 1, NULL, 0),
20768c2ecf20Sopenharmony_ci
20778c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("DL Digital Clock", SND_SOC_NOPM,
20788c2ecf20Sopenharmony_ci			    0, 0, NULL, 0),
20798c2ecf20Sopenharmony_ci
20808c2ecf20Sopenharmony_ci	/* AFE ON */
20818c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("AFE_ON", SUPPLY_SEQ_AFE,
20828c2ecf20Sopenharmony_ci			      MT6358_AFE_UL_DL_CON0, AFE_ON_SFT, 0,
20838c2ecf20Sopenharmony_ci			      NULL, 0),
20848c2ecf20Sopenharmony_ci
20858c2ecf20Sopenharmony_ci	/* AIF Rx*/
20868c2ecf20Sopenharmony_ci	SND_SOC_DAPM_AIF_IN_E("AIF_RX", "AIF1 Playback", 0,
20878c2ecf20Sopenharmony_ci			      MT6358_AFE_DL_SRC2_CON0_L,
20888c2ecf20Sopenharmony_ci			      DL_2_SRC_ON_TMP_CTL_PRE_SFT, 0,
20898c2ecf20Sopenharmony_ci			      mt_aif_in_event,
20908c2ecf20Sopenharmony_ci			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
20918c2ecf20Sopenharmony_ci
20928c2ecf20Sopenharmony_ci	/* DL Supply */
20938c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("DL Power Supply", SND_SOC_NOPM,
20948c2ecf20Sopenharmony_ci			    0, 0, NULL, 0),
20958c2ecf20Sopenharmony_ci
20968c2ecf20Sopenharmony_ci	/* DAC */
20978c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("DAC In Mux", SND_SOC_NOPM, 0, 0, &dac_in_mux_control),
20988c2ecf20Sopenharmony_ci
20998c2ecf20Sopenharmony_ci	SND_SOC_DAPM_DAC("DACL", NULL, SND_SOC_NOPM, 0, 0),
21008c2ecf20Sopenharmony_ci
21018c2ecf20Sopenharmony_ci	SND_SOC_DAPM_DAC("DACR", NULL, SND_SOC_NOPM, 0, 0),
21028c2ecf20Sopenharmony_ci
21038c2ecf20Sopenharmony_ci	/* LOL */
21048c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("LOL Mux", SND_SOC_NOPM, 0, 0, &lo_in_mux_control),
21058c2ecf20Sopenharmony_ci
21068c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("LO Stability Enh", MT6358_AUDDEC_ANA_CON7,
21078c2ecf20Sopenharmony_ci			    RG_LOOUTPUTSTBENH_VAUDP15_SFT, 0, NULL, 0),
21088c2ecf20Sopenharmony_ci
21098c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUT_DRV("LOL Buffer", MT6358_AUDDEC_ANA_CON7,
21108c2ecf20Sopenharmony_ci			     RG_AUDLOLPWRUP_VAUDP15_SFT, 0, NULL, 0),
21118c2ecf20Sopenharmony_ci
21128c2ecf20Sopenharmony_ci	/* Headphone */
21138c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX_E("HPL Mux", SND_SOC_NOPM, 0, 0,
21148c2ecf20Sopenharmony_ci			   &hpl_in_mux_control,
21158c2ecf20Sopenharmony_ci			   mt_hp_event,
21168c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMU |
21178c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMD),
21188c2ecf20Sopenharmony_ci
21198c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX_E("HPR Mux", SND_SOC_NOPM, 0, 0,
21208c2ecf20Sopenharmony_ci			   &hpr_in_mux_control,
21218c2ecf20Sopenharmony_ci			   mt_hp_event,
21228c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMU |
21238c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMD),
21248c2ecf20Sopenharmony_ci
21258c2ecf20Sopenharmony_ci	/* Receiver */
21268c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX_E("RCV Mux", SND_SOC_NOPM, 0, 0,
21278c2ecf20Sopenharmony_ci			   &rcv_in_mux_control,
21288c2ecf20Sopenharmony_ci			   mt_rcv_event,
21298c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMU |
21308c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMD),
21318c2ecf20Sopenharmony_ci
21328c2ecf20Sopenharmony_ci	/* Outputs */
21338c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("Receiver"),
21348c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("Headphone L"),
21358c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("Headphone R"),
21368c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("Headphone L Ext Spk Amp"),
21378c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("Headphone R Ext Spk Amp"),
21388c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("LINEOUT L"),
21398c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("LINEOUT L HSSPK"),
21408c2ecf20Sopenharmony_ci
21418c2ecf20Sopenharmony_ci	/* SGEN */
21428c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("SGEN DL Enable", MT6358_AFE_SGEN_CFG0,
21438c2ecf20Sopenharmony_ci			    SGEN_DAC_EN_CTL_SFT, 0, NULL, 0),
21448c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("SGEN MUTE", MT6358_AFE_SGEN_CFG0,
21458c2ecf20Sopenharmony_ci			    SGEN_MUTE_SW_CTL_SFT, 1,
21468c2ecf20Sopenharmony_ci			    mt_sgen_event,
21478c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
21488c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("SGEN DL SRC", MT6358_AFE_DL_SRC2_CON0_L,
21498c2ecf20Sopenharmony_ci			    DL_2_SRC_ON_TMP_CTL_PRE_SFT, 0, NULL, 0),
21508c2ecf20Sopenharmony_ci
21518c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("SGEN DL"),
21528c2ecf20Sopenharmony_ci
21538c2ecf20Sopenharmony_ci	/* Uplinks */
21548c2ecf20Sopenharmony_ci	SND_SOC_DAPM_AIF_OUT_E("AIF1TX", "AIF1 Capture", 0,
21558c2ecf20Sopenharmony_ci			       SND_SOC_NOPM, 0, 0,
21568c2ecf20Sopenharmony_ci			       mt_aif_out_event,
21578c2ecf20Sopenharmony_ci			       SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
21588c2ecf20Sopenharmony_ci
21598c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("ADC Supply", SUPPLY_SEQ_ADC_SUPPLY,
21608c2ecf20Sopenharmony_ci			      SND_SOC_NOPM, 0, 0,
21618c2ecf20Sopenharmony_ci			      mt_adc_supply_event,
21628c2ecf20Sopenharmony_ci			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
21638c2ecf20Sopenharmony_ci
21648c2ecf20Sopenharmony_ci	/* Uplinks MUX */
21658c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("AIF Out Mux", SND_SOC_NOPM, 0, 0,
21668c2ecf20Sopenharmony_ci			 &aif_out_mux_control),
21678c2ecf20Sopenharmony_ci
21688c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX_E("Mic Type Mux", SND_SOC_NOPM, 0, 0,
21698c2ecf20Sopenharmony_ci			   &mic_type_mux_control,
21708c2ecf20Sopenharmony_ci			   mt_mic_type_event,
21718c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD |
21728c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_WILL_PMU),
21738c2ecf20Sopenharmony_ci
21748c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX_E("ADC L Mux", SND_SOC_NOPM, 0, 0,
21758c2ecf20Sopenharmony_ci			   &adc_left_mux_control,
21768c2ecf20Sopenharmony_ci			   mt_adc_l_event,
21778c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_WILL_PMU),
21788c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX_E("ADC R Mux", SND_SOC_NOPM, 0, 0,
21798c2ecf20Sopenharmony_ci			   &adc_right_mux_control,
21808c2ecf20Sopenharmony_ci			   mt_adc_r_event,
21818c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_WILL_PMU),
21828c2ecf20Sopenharmony_ci
21838c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("ADC L", NULL, SND_SOC_NOPM, 0, 0),
21848c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("ADC R", NULL, SND_SOC_NOPM, 0, 0),
21858c2ecf20Sopenharmony_ci
21868c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX_E("PGA L Mux", SND_SOC_NOPM, 0, 0,
21878c2ecf20Sopenharmony_ci			   &pga_left_mux_control,
21888c2ecf20Sopenharmony_ci			   mt_pga_left_event,
21898c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_WILL_PMU),
21908c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX_E("PGA R Mux", SND_SOC_NOPM, 0, 0,
21918c2ecf20Sopenharmony_ci			   &pga_right_mux_control,
21928c2ecf20Sopenharmony_ci			   mt_pga_right_event,
21938c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_WILL_PMU),
21948c2ecf20Sopenharmony_ci
21958c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("PGA L", SND_SOC_NOPM, 0, 0, NULL, 0),
21968c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("PGA R", SND_SOC_NOPM, 0, 0, NULL, 0),
21978c2ecf20Sopenharmony_ci
21988c2ecf20Sopenharmony_ci	/* UL input */
21998c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AIN0"),
22008c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AIN1"),
22018c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AIN2"),
22028c2ecf20Sopenharmony_ci};
22038c2ecf20Sopenharmony_ci
22048c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route mt6358_dapm_routes[] = {
22058c2ecf20Sopenharmony_ci	/* Capture */
22068c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AIF Out Mux"},
22078c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "CLK_BUF"},
22088c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDGLB"},
22098c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "CLKSQ Audio"},
22108c2ecf20Sopenharmony_ci
22118c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUD_CK"},
22128c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDIF_CK"},
22138c2ecf20Sopenharmony_ci
22148c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDIO_TOP_AFE_CTL"},
22158c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDIO_TOP_ADC_CTL"},
22168c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDIO_TOP_PWR_CLK"},
22178c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDIO_TOP_PDN_RESERVED"},
22188c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDIO_TOP_I2S_DL"},
22198c2ecf20Sopenharmony_ci
22208c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AFE_ON"},
22218c2ecf20Sopenharmony_ci
22228c2ecf20Sopenharmony_ci	{"AIF Out Mux", NULL, "Mic Type Mux"},
22238c2ecf20Sopenharmony_ci
22248c2ecf20Sopenharmony_ci	{"Mic Type Mux", "ACC", "ADC L"},
22258c2ecf20Sopenharmony_ci	{"Mic Type Mux", "ACC", "ADC R"},
22268c2ecf20Sopenharmony_ci	{"Mic Type Mux", "DCC", "ADC L"},
22278c2ecf20Sopenharmony_ci	{"Mic Type Mux", "DCC", "ADC R"},
22288c2ecf20Sopenharmony_ci	{"Mic Type Mux", "DCC_ECM_DIFF", "ADC L"},
22298c2ecf20Sopenharmony_ci	{"Mic Type Mux", "DCC_ECM_DIFF", "ADC R"},
22308c2ecf20Sopenharmony_ci	{"Mic Type Mux", "DCC_ECM_SINGLE", "ADC L"},
22318c2ecf20Sopenharmony_ci	{"Mic Type Mux", "DCC_ECM_SINGLE", "ADC R"},
22328c2ecf20Sopenharmony_ci	{"Mic Type Mux", "DMIC", "AIN0"},
22338c2ecf20Sopenharmony_ci	{"Mic Type Mux", "DMIC", "AIN2"},
22348c2ecf20Sopenharmony_ci
22358c2ecf20Sopenharmony_ci	{"ADC L", NULL, "ADC L Mux"},
22368c2ecf20Sopenharmony_ci	{"ADC L", NULL, "ADC Supply"},
22378c2ecf20Sopenharmony_ci	{"ADC R", NULL, "ADC R Mux"},
22388c2ecf20Sopenharmony_ci	{"ADC R", NULL, "ADC Supply"},
22398c2ecf20Sopenharmony_ci
22408c2ecf20Sopenharmony_ci	{"ADC L Mux", "Left Preamplifier", "PGA L"},
22418c2ecf20Sopenharmony_ci
22428c2ecf20Sopenharmony_ci	{"ADC R Mux", "Right Preamplifier", "PGA R"},
22438c2ecf20Sopenharmony_ci
22448c2ecf20Sopenharmony_ci	{"PGA L", NULL, "PGA L Mux"},
22458c2ecf20Sopenharmony_ci	{"PGA R", NULL, "PGA R Mux"},
22468c2ecf20Sopenharmony_ci
22478c2ecf20Sopenharmony_ci	{"PGA L Mux", "AIN0", "AIN0"},
22488c2ecf20Sopenharmony_ci	{"PGA L Mux", "AIN1", "AIN1"},
22498c2ecf20Sopenharmony_ci	{"PGA L Mux", "AIN2", "AIN2"},
22508c2ecf20Sopenharmony_ci
22518c2ecf20Sopenharmony_ci	{"PGA R Mux", "AIN0", "AIN0"},
22528c2ecf20Sopenharmony_ci	{"PGA R Mux", "AIN1", "AIN1"},
22538c2ecf20Sopenharmony_ci	{"PGA R Mux", "AIN2", "AIN2"},
22548c2ecf20Sopenharmony_ci
22558c2ecf20Sopenharmony_ci	/* DL Supply */
22568c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "CLK_BUF"},
22578c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "AUDGLB"},
22588c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "CLKSQ Audio"},
22598c2ecf20Sopenharmony_ci
22608c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "AUDNCP_CK"},
22618c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "ZCD13M_CK"},
22628c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "AUD_CK"},
22638c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "AUDIF_CK"},
22648c2ecf20Sopenharmony_ci
22658c2ecf20Sopenharmony_ci	/* DL Digital Supply */
22668c2ecf20Sopenharmony_ci	{"DL Digital Clock", NULL, "AUDIO_TOP_AFE_CTL"},
22678c2ecf20Sopenharmony_ci	{"DL Digital Clock", NULL, "AUDIO_TOP_DAC_CTL"},
22688c2ecf20Sopenharmony_ci	{"DL Digital Clock", NULL, "AUDIO_TOP_PWR_CLK"},
22698c2ecf20Sopenharmony_ci
22708c2ecf20Sopenharmony_ci	{"DL Digital Clock", NULL, "AFE_ON"},
22718c2ecf20Sopenharmony_ci
22728c2ecf20Sopenharmony_ci	{"AIF_RX", NULL, "DL Digital Clock"},
22738c2ecf20Sopenharmony_ci
22748c2ecf20Sopenharmony_ci	/* DL Path */
22758c2ecf20Sopenharmony_ci	{"DAC In Mux", "Normal Path", "AIF_RX"},
22768c2ecf20Sopenharmony_ci
22778c2ecf20Sopenharmony_ci	{"DAC In Mux", "Sgen", "SGEN DL"},
22788c2ecf20Sopenharmony_ci	{"SGEN DL", NULL, "SGEN DL SRC"},
22798c2ecf20Sopenharmony_ci	{"SGEN DL", NULL, "SGEN MUTE"},
22808c2ecf20Sopenharmony_ci	{"SGEN DL", NULL, "SGEN DL Enable"},
22818c2ecf20Sopenharmony_ci	{"SGEN DL", NULL, "DL Digital Clock"},
22828c2ecf20Sopenharmony_ci	{"SGEN DL", NULL, "AUDIO_TOP_PDN_AFE_TESTMODEL"},
22838c2ecf20Sopenharmony_ci
22848c2ecf20Sopenharmony_ci	{"DACL", NULL, "DAC In Mux"},
22858c2ecf20Sopenharmony_ci	{"DACL", NULL, "DL Power Supply"},
22868c2ecf20Sopenharmony_ci
22878c2ecf20Sopenharmony_ci	{"DACR", NULL, "DAC In Mux"},
22888c2ecf20Sopenharmony_ci	{"DACR", NULL, "DL Power Supply"},
22898c2ecf20Sopenharmony_ci
22908c2ecf20Sopenharmony_ci	/* Lineout Path */
22918c2ecf20Sopenharmony_ci	{"LOL Mux", "Playback", "DACL"},
22928c2ecf20Sopenharmony_ci
22938c2ecf20Sopenharmony_ci	{"LOL Buffer", NULL, "LOL Mux"},
22948c2ecf20Sopenharmony_ci	{"LOL Buffer", NULL, "LO Stability Enh"},
22958c2ecf20Sopenharmony_ci
22968c2ecf20Sopenharmony_ci	{"LINEOUT L", NULL, "LOL Buffer"},
22978c2ecf20Sopenharmony_ci
22988c2ecf20Sopenharmony_ci	/* Headphone Path */
22998c2ecf20Sopenharmony_ci	{"HPL Mux", "Audio Playback", "DACL"},
23008c2ecf20Sopenharmony_ci	{"HPR Mux", "Audio Playback", "DACR"},
23018c2ecf20Sopenharmony_ci	{"HPL Mux", "HP Impedance", "DACL"},
23028c2ecf20Sopenharmony_ci	{"HPR Mux", "HP Impedance", "DACR"},
23038c2ecf20Sopenharmony_ci	{"HPL Mux", "LoudSPK Playback", "DACL"},
23048c2ecf20Sopenharmony_ci	{"HPR Mux", "LoudSPK Playback", "DACR"},
23058c2ecf20Sopenharmony_ci
23068c2ecf20Sopenharmony_ci	{"Headphone L", NULL, "HPL Mux"},
23078c2ecf20Sopenharmony_ci	{"Headphone R", NULL, "HPR Mux"},
23088c2ecf20Sopenharmony_ci	{"Headphone L Ext Spk Amp", NULL, "HPL Mux"},
23098c2ecf20Sopenharmony_ci	{"Headphone R Ext Spk Amp", NULL, "HPR Mux"},
23108c2ecf20Sopenharmony_ci	{"LINEOUT L HSSPK", NULL, "HPL Mux"},
23118c2ecf20Sopenharmony_ci
23128c2ecf20Sopenharmony_ci	/* Receiver Path */
23138c2ecf20Sopenharmony_ci	{"RCV Mux", "Voice Playback", "DACL"},
23148c2ecf20Sopenharmony_ci	{"Receiver", NULL, "RCV Mux"},
23158c2ecf20Sopenharmony_ci};
23168c2ecf20Sopenharmony_ci
23178c2ecf20Sopenharmony_cistatic int mt6358_codec_dai_hw_params(struct snd_pcm_substream *substream,
23188c2ecf20Sopenharmony_ci				      struct snd_pcm_hw_params *params,
23198c2ecf20Sopenharmony_ci				      struct snd_soc_dai *dai)
23208c2ecf20Sopenharmony_ci{
23218c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = dai->component;
23228c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
23238c2ecf20Sopenharmony_ci	unsigned int rate = params_rate(params);
23248c2ecf20Sopenharmony_ci
23258c2ecf20Sopenharmony_ci	dev_info(priv->dev, "%s(), substream->stream %d, rate %d, number %d\n",
23268c2ecf20Sopenharmony_ci		 __func__,
23278c2ecf20Sopenharmony_ci		 substream->stream,
23288c2ecf20Sopenharmony_ci		 rate,
23298c2ecf20Sopenharmony_ci		 substream->number);
23308c2ecf20Sopenharmony_ci
23318c2ecf20Sopenharmony_ci	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
23328c2ecf20Sopenharmony_ci		priv->dl_rate = rate;
23338c2ecf20Sopenharmony_ci	else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
23348c2ecf20Sopenharmony_ci		priv->ul_rate = rate;
23358c2ecf20Sopenharmony_ci
23368c2ecf20Sopenharmony_ci	return 0;
23378c2ecf20Sopenharmony_ci}
23388c2ecf20Sopenharmony_ci
23398c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops mt6358_codec_dai_ops = {
23408c2ecf20Sopenharmony_ci	.hw_params = mt6358_codec_dai_hw_params,
23418c2ecf20Sopenharmony_ci};
23428c2ecf20Sopenharmony_ci
23438c2ecf20Sopenharmony_ci#define MT6358_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |\
23448c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE |\
23458c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |\
23468c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE |\
23478c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |\
23488c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE)
23498c2ecf20Sopenharmony_ci
23508c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver mt6358_dai_driver[] = {
23518c2ecf20Sopenharmony_ci	{
23528c2ecf20Sopenharmony_ci		.name = "mt6358-snd-codec-aif1",
23538c2ecf20Sopenharmony_ci		.playback = {
23548c2ecf20Sopenharmony_ci			.stream_name = "AIF1 Playback",
23558c2ecf20Sopenharmony_ci			.channels_min = 1,
23568c2ecf20Sopenharmony_ci			.channels_max = 2,
23578c2ecf20Sopenharmony_ci			.rates = SNDRV_PCM_RATE_8000_48000 |
23588c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_96000 |
23598c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_192000,
23608c2ecf20Sopenharmony_ci			.formats = MT6358_FORMATS,
23618c2ecf20Sopenharmony_ci		},
23628c2ecf20Sopenharmony_ci		.capture = {
23638c2ecf20Sopenharmony_ci			.stream_name = "AIF1 Capture",
23648c2ecf20Sopenharmony_ci			.channels_min = 1,
23658c2ecf20Sopenharmony_ci			.channels_max = 2,
23668c2ecf20Sopenharmony_ci			.rates = SNDRV_PCM_RATE_8000 |
23678c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_16000 |
23688c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_32000 |
23698c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_48000,
23708c2ecf20Sopenharmony_ci			.formats = MT6358_FORMATS,
23718c2ecf20Sopenharmony_ci		},
23728c2ecf20Sopenharmony_ci		.ops = &mt6358_codec_dai_ops,
23738c2ecf20Sopenharmony_ci	},
23748c2ecf20Sopenharmony_ci};
23758c2ecf20Sopenharmony_ci
23768c2ecf20Sopenharmony_cistatic void mt6358_codec_init_reg(struct mt6358_priv *priv)
23778c2ecf20Sopenharmony_ci{
23788c2ecf20Sopenharmony_ci	/* Disable HeadphoneL/HeadphoneR short circuit protection */
23798c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON0,
23808c2ecf20Sopenharmony_ci			   RG_AUDHPLSCDISABLE_VAUDP15_MASK_SFT,
23818c2ecf20Sopenharmony_ci			   0x1 << RG_AUDHPLSCDISABLE_VAUDP15_SFT);
23828c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON0,
23838c2ecf20Sopenharmony_ci			   RG_AUDHPRSCDISABLE_VAUDP15_MASK_SFT,
23848c2ecf20Sopenharmony_ci			   0x1 << RG_AUDHPRSCDISABLE_VAUDP15_SFT);
23858c2ecf20Sopenharmony_ci	/* Disable voice short circuit protection */
23868c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON6,
23878c2ecf20Sopenharmony_ci			   RG_AUDHSSCDISABLE_VAUDP15_MASK_SFT,
23888c2ecf20Sopenharmony_ci			   0x1 << RG_AUDHSSCDISABLE_VAUDP15_SFT);
23898c2ecf20Sopenharmony_ci	/* disable LO buffer left short circuit protection */
23908c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_AUDDEC_ANA_CON7,
23918c2ecf20Sopenharmony_ci			   RG_AUDLOLSCDISABLE_VAUDP15_MASK_SFT,
23928c2ecf20Sopenharmony_ci			   0x1 << RG_AUDLOLSCDISABLE_VAUDP15_SFT);
23938c2ecf20Sopenharmony_ci
23948c2ecf20Sopenharmony_ci	/* accdet s/w enable */
23958c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, MT6358_ACCDET_CON13,
23968c2ecf20Sopenharmony_ci			   0xFFFF, 0x700E);
23978c2ecf20Sopenharmony_ci
23988c2ecf20Sopenharmony_ci	/* gpio miso driving set to 4mA */
23998c2ecf20Sopenharmony_ci	regmap_write(priv->regmap, MT6358_DRV_CON3, 0x8888);
24008c2ecf20Sopenharmony_ci
24018c2ecf20Sopenharmony_ci	/* set gpio */
24028c2ecf20Sopenharmony_ci	playback_gpio_reset(priv);
24038c2ecf20Sopenharmony_ci	capture_gpio_reset(priv);
24048c2ecf20Sopenharmony_ci}
24058c2ecf20Sopenharmony_ci
24068c2ecf20Sopenharmony_cistatic int mt6358_codec_probe(struct snd_soc_component *cmpnt)
24078c2ecf20Sopenharmony_ci{
24088c2ecf20Sopenharmony_ci	struct mt6358_priv *priv = snd_soc_component_get_drvdata(cmpnt);
24098c2ecf20Sopenharmony_ci	int ret;
24108c2ecf20Sopenharmony_ci
24118c2ecf20Sopenharmony_ci	snd_soc_component_init_regmap(cmpnt, priv->regmap);
24128c2ecf20Sopenharmony_ci
24138c2ecf20Sopenharmony_ci	mt6358_codec_init_reg(priv);
24148c2ecf20Sopenharmony_ci
24158c2ecf20Sopenharmony_ci	priv->avdd_reg = devm_regulator_get(priv->dev, "Avdd");
24168c2ecf20Sopenharmony_ci	if (IS_ERR(priv->avdd_reg)) {
24178c2ecf20Sopenharmony_ci		dev_err(priv->dev, "%s() have no Avdd supply", __func__);
24188c2ecf20Sopenharmony_ci		return PTR_ERR(priv->avdd_reg);
24198c2ecf20Sopenharmony_ci	}
24208c2ecf20Sopenharmony_ci
24218c2ecf20Sopenharmony_ci	ret = regulator_enable(priv->avdd_reg);
24228c2ecf20Sopenharmony_ci	if (ret)
24238c2ecf20Sopenharmony_ci		return  ret;
24248c2ecf20Sopenharmony_ci
24258c2ecf20Sopenharmony_ci	return 0;
24268c2ecf20Sopenharmony_ci}
24278c2ecf20Sopenharmony_ci
24288c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver mt6358_soc_component_driver = {
24298c2ecf20Sopenharmony_ci	.probe = mt6358_codec_probe,
24308c2ecf20Sopenharmony_ci	.controls = mt6358_snd_controls,
24318c2ecf20Sopenharmony_ci	.num_controls = ARRAY_SIZE(mt6358_snd_controls),
24328c2ecf20Sopenharmony_ci	.dapm_widgets = mt6358_dapm_widgets,
24338c2ecf20Sopenharmony_ci	.num_dapm_widgets = ARRAY_SIZE(mt6358_dapm_widgets),
24348c2ecf20Sopenharmony_ci	.dapm_routes = mt6358_dapm_routes,
24358c2ecf20Sopenharmony_ci	.num_dapm_routes = ARRAY_SIZE(mt6358_dapm_routes),
24368c2ecf20Sopenharmony_ci};
24378c2ecf20Sopenharmony_ci
24388c2ecf20Sopenharmony_cistatic void mt6358_parse_dt(struct mt6358_priv *priv)
24398c2ecf20Sopenharmony_ci{
24408c2ecf20Sopenharmony_ci	int ret;
24418c2ecf20Sopenharmony_ci	struct device *dev = priv->dev;
24428c2ecf20Sopenharmony_ci
24438c2ecf20Sopenharmony_ci	ret = of_property_read_u32(dev->of_node, "mediatek,dmic-mode",
24448c2ecf20Sopenharmony_ci				   &priv->dmic_one_wire_mode);
24458c2ecf20Sopenharmony_ci	if (ret) {
24468c2ecf20Sopenharmony_ci		dev_warn(priv->dev, "%s() failed to read dmic-mode\n",
24478c2ecf20Sopenharmony_ci			 __func__);
24488c2ecf20Sopenharmony_ci		priv->dmic_one_wire_mode = 0;
24498c2ecf20Sopenharmony_ci	}
24508c2ecf20Sopenharmony_ci}
24518c2ecf20Sopenharmony_ci
24528c2ecf20Sopenharmony_cistatic int mt6358_platform_driver_probe(struct platform_device *pdev)
24538c2ecf20Sopenharmony_ci{
24548c2ecf20Sopenharmony_ci	struct mt6358_priv *priv;
24558c2ecf20Sopenharmony_ci	struct mt6397_chip *mt6397 = dev_get_drvdata(pdev->dev.parent);
24568c2ecf20Sopenharmony_ci
24578c2ecf20Sopenharmony_ci	priv = devm_kzalloc(&pdev->dev,
24588c2ecf20Sopenharmony_ci			    sizeof(struct mt6358_priv),
24598c2ecf20Sopenharmony_ci			    GFP_KERNEL);
24608c2ecf20Sopenharmony_ci	if (!priv)
24618c2ecf20Sopenharmony_ci		return -ENOMEM;
24628c2ecf20Sopenharmony_ci
24638c2ecf20Sopenharmony_ci	dev_set_drvdata(&pdev->dev, priv);
24648c2ecf20Sopenharmony_ci
24658c2ecf20Sopenharmony_ci	priv->dev = &pdev->dev;
24668c2ecf20Sopenharmony_ci
24678c2ecf20Sopenharmony_ci	priv->regmap = mt6397->regmap;
24688c2ecf20Sopenharmony_ci	if (IS_ERR(priv->regmap))
24698c2ecf20Sopenharmony_ci		return PTR_ERR(priv->regmap);
24708c2ecf20Sopenharmony_ci
24718c2ecf20Sopenharmony_ci	mt6358_parse_dt(priv);
24728c2ecf20Sopenharmony_ci
24738c2ecf20Sopenharmony_ci	dev_info(priv->dev, "%s(), dev name %s\n",
24748c2ecf20Sopenharmony_ci		 __func__, dev_name(&pdev->dev));
24758c2ecf20Sopenharmony_ci
24768c2ecf20Sopenharmony_ci	return devm_snd_soc_register_component(&pdev->dev,
24778c2ecf20Sopenharmony_ci				      &mt6358_soc_component_driver,
24788c2ecf20Sopenharmony_ci				      mt6358_dai_driver,
24798c2ecf20Sopenharmony_ci				      ARRAY_SIZE(mt6358_dai_driver));
24808c2ecf20Sopenharmony_ci}
24818c2ecf20Sopenharmony_ci
24828c2ecf20Sopenharmony_cistatic const struct of_device_id mt6358_of_match[] = {
24838c2ecf20Sopenharmony_ci	{.compatible = "mediatek,mt6358-sound",},
24848c2ecf20Sopenharmony_ci	{}
24858c2ecf20Sopenharmony_ci};
24868c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, mt6358_of_match);
24878c2ecf20Sopenharmony_ci
24888c2ecf20Sopenharmony_cistatic struct platform_driver mt6358_platform_driver = {
24898c2ecf20Sopenharmony_ci	.driver = {
24908c2ecf20Sopenharmony_ci		.name = "mt6358-sound",
24918c2ecf20Sopenharmony_ci		.of_match_table = mt6358_of_match,
24928c2ecf20Sopenharmony_ci	},
24938c2ecf20Sopenharmony_ci	.probe = mt6358_platform_driver_probe,
24948c2ecf20Sopenharmony_ci};
24958c2ecf20Sopenharmony_ci
24968c2ecf20Sopenharmony_cimodule_platform_driver(mt6358_platform_driver)
24978c2ecf20Sopenharmony_ci
24988c2ecf20Sopenharmony_ci/* Module information */
24998c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("MT6358 ALSA SoC codec driver");
25008c2ecf20Sopenharmony_ciMODULE_AUTHOR("KaiChieh Chuang <kaichieh.chuang@mediatek.com>");
25018c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
2502