18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci//
38c2ecf20Sopenharmony_ci// mt6351.c  --  mt6351 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/dma-mapping.h>
98c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
108c2ecf20Sopenharmony_ci#include <linux/slab.h>
118c2ecf20Sopenharmony_ci#include <linux/module.h>
128c2ecf20Sopenharmony_ci#include <linux/of_device.h>
138c2ecf20Sopenharmony_ci#include <linux/delay.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <sound/core.h>
168c2ecf20Sopenharmony_ci#include <sound/pcm.h>
178c2ecf20Sopenharmony_ci#include <sound/soc.h>
188c2ecf20Sopenharmony_ci#include <sound/tlv.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include "mt6351.h"
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/* MT6351_TOP_CLKSQ */
238c2ecf20Sopenharmony_ci#define RG_CLKSQ_EN_AUD_BIT (0)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* MT6351_TOP_CKPDN_CON0 */
268c2ecf20Sopenharmony_ci#define RG_AUDNCP_CK_PDN_BIT (12)
278c2ecf20Sopenharmony_ci#define RG_AUDIF_CK_PDN_BIT (13)
288c2ecf20Sopenharmony_ci#define RG_AUD_CK_PDN_BIT (14)
298c2ecf20Sopenharmony_ci#define RG_ZCD13M_CK_PDN_BIT (15)
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* MT6351_AUDDEC_ANA_CON0 */
328c2ecf20Sopenharmony_ci#define RG_AUDDACLPWRUP_VAUDP32_BIT (0)
338c2ecf20Sopenharmony_ci#define RG_AUDDACRPWRUP_VAUDP32_BIT (1)
348c2ecf20Sopenharmony_ci#define RG_AUD_DAC_PWR_UP_VA32_BIT (2)
358c2ecf20Sopenharmony_ci#define RG_AUD_DAC_PWL_UP_VA32_BIT (3)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define RG_AUDHSPWRUP_VAUDP32_BIT (4)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define RG_AUDHPLPWRUP_VAUDP32_BIT (5)
408c2ecf20Sopenharmony_ci#define RG_AUDHPRPWRUP_VAUDP32_BIT (6)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define RG_AUDHSMUXINPUTSEL_VAUDP32_SFT (7)
438c2ecf20Sopenharmony_ci#define RG_AUDHSMUXINPUTSEL_VAUDP32_MASK (0x3)
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define RG_AUDHPLMUXINPUTSEL_VAUDP32_SFT (9)
468c2ecf20Sopenharmony_ci#define RG_AUDHPLMUXINPUTSEL_VAUDP32_MASK (0x3)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define RG_AUDHPRMUXINPUTSEL_VAUDP32_SFT (11)
498c2ecf20Sopenharmony_ci#define RG_AUDHPRMUXINPUTSEL_VAUDP32_MASK (0x3)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define RG_AUDHSSCDISABLE_VAUDP32 (13)
528c2ecf20Sopenharmony_ci#define RG_AUDHPLSCDISABLE_VAUDP32_BIT (14)
538c2ecf20Sopenharmony_ci#define RG_AUDHPRSCDISABLE_VAUDP32_BIT (15)
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* MT6351_AUDDEC_ANA_CON1 */
568c2ecf20Sopenharmony_ci#define RG_HSOUTPUTSTBENH_VAUDP32_BIT (8)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/* MT6351_AUDDEC_ANA_CON3 */
598c2ecf20Sopenharmony_ci#define RG_AUDLOLPWRUP_VAUDP32_BIT (2)
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define RG_AUDLOLMUXINPUTSEL_VAUDP32_SFT (3)
628c2ecf20Sopenharmony_ci#define RG_AUDLOLMUXINPUTSEL_VAUDP32_MASK (0x3)
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define RG_AUDLOLSCDISABLE_VAUDP32_BIT (5)
658c2ecf20Sopenharmony_ci#define RG_LOOUTPUTSTBENH_VAUDP32_BIT (9)
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/* MT6351_AUDDEC_ANA_CON6 */
688c2ecf20Sopenharmony_ci#define RG_ABIDEC_RSVD0_VAUDP32_HPL_BIT (8)
698c2ecf20Sopenharmony_ci#define RG_ABIDEC_RSVD0_VAUDP32_HPR_BIT (9)
708c2ecf20Sopenharmony_ci#define RG_ABIDEC_RSVD0_VAUDP32_HS_BIT (10)
718c2ecf20Sopenharmony_ci#define RG_ABIDEC_RSVD0_VAUDP32_LOL_BIT (11)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* MT6351_AUDDEC_ANA_CON9 */
748c2ecf20Sopenharmony_ci#define RG_AUDIBIASPWRDN_VAUDP32_BIT (8)
758c2ecf20Sopenharmony_ci#define RG_RSTB_DECODER_VA32_BIT (9)
768c2ecf20Sopenharmony_ci#define RG_AUDGLB_PWRDN_VA32_BIT (12)
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define RG_LCLDO_DEC_EN_VA32_BIT (13)
798c2ecf20Sopenharmony_ci#define RG_LCLDO_DEC_REMOTE_SENSE_VA18_BIT (15)
808c2ecf20Sopenharmony_ci/* MT6351_AUDDEC_ANA_CON10 */
818c2ecf20Sopenharmony_ci#define RG_NVREG_EN_VAUDP32_BIT (8)
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define RG_AUDGLB_LP2_VOW_EN_VA32 10
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* MT6351_AFE_UL_DL_CON0 */
868c2ecf20Sopenharmony_ci#define RG_AFE_ON_BIT (0)
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/* MT6351_AFE_DL_SRC2_CON0_L */
898c2ecf20Sopenharmony_ci#define RG_DL_2_SRC_ON_TMP_CTL_PRE_BIT (0)
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/* MT6351_AFE_UL_SRC_CON0_L */
928c2ecf20Sopenharmony_ci#define UL_SRC_ON_TMP_CTL (0)
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/* MT6351_AFE_TOP_CON0 */
958c2ecf20Sopenharmony_ci#define RG_DL_SINE_ON_SFT (0)
968c2ecf20Sopenharmony_ci#define RG_DL_SINE_ON_MASK (0x1)
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#define RG_UL_SINE_ON_SFT (1)
998c2ecf20Sopenharmony_ci#define RG_UL_SINE_ON_MASK (0x1)
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/* MT6351_AUDIO_TOP_CON0 */
1028c2ecf20Sopenharmony_ci#define AUD_TOP_PDN_RESERVED_BIT 0
1038c2ecf20Sopenharmony_ci#define AUD_TOP_PWR_CLK_DIS_CTL_BIT 2
1048c2ecf20Sopenharmony_ci#define AUD_TOP_PDN_ADC_CTL_BIT 5
1058c2ecf20Sopenharmony_ci#define AUD_TOP_PDN_DAC_CTL_BIT 6
1068c2ecf20Sopenharmony_ci#define AUD_TOP_PDN_AFE_CTL_BIT 7
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* MT6351_AFE_SGEN_CFG0 */
1098c2ecf20Sopenharmony_ci#define SGEN_C_MUTE_SW_CTL_BIT 6
1108c2ecf20Sopenharmony_ci#define SGEN_C_DAC_EN_CTL_BIT 7
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/* MT6351_AFE_NCP_CFG0 */
1138c2ecf20Sopenharmony_ci#define RG_NCP_ON_BIT 0
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/* MT6351_LDO_VUSB33_CON0 */
1168c2ecf20Sopenharmony_ci#define RG_VUSB33_EN 1
1178c2ecf20Sopenharmony_ci#define RG_VUSB33_ON_CTRL 3
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci/* MT6351_LDO_VA18_CON0 */
1208c2ecf20Sopenharmony_ci#define RG_VA18_EN 1
1218c2ecf20Sopenharmony_ci#define RG_VA18_ON_CTRL 3
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci/* MT6351_AUDENC_ANA_CON0 */
1248c2ecf20Sopenharmony_ci#define RG_AUDPREAMPLON 0
1258c2ecf20Sopenharmony_ci#define RG_AUDPREAMPLDCCEN 1
1268c2ecf20Sopenharmony_ci#define RG_AUDPREAMPLDCPRECHARGE 2
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define RG_AUDPREAMPLINPUTSEL_SFT (4)
1298c2ecf20Sopenharmony_ci#define RG_AUDPREAMPLINPUTSEL_MASK (0x3)
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci#define RG_AUDADCLPWRUP 12
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci#define RG_AUDADCLINPUTSEL_SFT (13)
1348c2ecf20Sopenharmony_ci#define RG_AUDADCLINPUTSEL_MASK (0x3)
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci/* MT6351_AUDENC_ANA_CON1 */
1378c2ecf20Sopenharmony_ci#define RG_AUDPREAMPRON 0
1388c2ecf20Sopenharmony_ci#define RG_AUDPREAMPRDCCEN 1
1398c2ecf20Sopenharmony_ci#define RG_AUDPREAMPRDCPRECHARGE 2
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define RG_AUDPREAMPRINPUTSEL_SFT (4)
1428c2ecf20Sopenharmony_ci#define RG_AUDPREAMPRINPUTSEL_MASK (0x3)
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#define RG_AUDADCRPWRUP 12
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci#define RG_AUDADCRINPUTSEL_SFT (13)
1478c2ecf20Sopenharmony_ci#define RG_AUDADCRINPUTSEL_MASK (0x3)
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci/* MT6351_AUDENC_ANA_CON3 */
1508c2ecf20Sopenharmony_ci#define RG_AUDADCCLKRSTB 6
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/* MT6351_AUDENC_ANA_CON9 */
1538c2ecf20Sopenharmony_ci#define RG_AUDPWDBMICBIAS0 0
1548c2ecf20Sopenharmony_ci#define RG_AUDMICBIAS0VREF 4
1558c2ecf20Sopenharmony_ci#define RG_AUDMICBIAS0LOWPEN 7
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci#define RG_AUDPWDBMICBIAS2 8
1588c2ecf20Sopenharmony_ci#define RG_AUDMICBIAS2VREF 12
1598c2ecf20Sopenharmony_ci#define RG_AUDMICBIAS2LOWPEN 15
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/* MT6351_AUDENC_ANA_CON10 */
1628c2ecf20Sopenharmony_ci#define RG_AUDPWDBMICBIAS1 0
1638c2ecf20Sopenharmony_ci#define RG_AUDMICBIAS1DCSW1NEN 2
1648c2ecf20Sopenharmony_ci#define RG_AUDMICBIAS1VREF 4
1658c2ecf20Sopenharmony_ci#define RG_AUDMICBIAS1LOWPEN 7
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cienum {
1688c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_HSOUTL,
1698c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_HSOUTR,
1708c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_HPOUTL,
1718c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_HPOUTR,
1728c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_LINEOUTL,
1738c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_LINEOUTR,
1748c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_MICAMP1,
1758c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_MICAMP2,
1768c2ecf20Sopenharmony_ci	AUDIO_ANALOG_VOLUME_TYPE_MAX
1778c2ecf20Sopenharmony_ci};
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci/* Supply subseq */
1808c2ecf20Sopenharmony_cienum {
1818c2ecf20Sopenharmony_ci	SUPPLY_SUBSEQ_SETTING,
1828c2ecf20Sopenharmony_ci	SUPPLY_SUBSEQ_ENABLE,
1838c2ecf20Sopenharmony_ci	SUPPLY_SUBSEQ_MICBIAS,
1848c2ecf20Sopenharmony_ci};
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci#define REG_STRIDE 2
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_cistruct mt6351_priv {
1898c2ecf20Sopenharmony_ci	struct device *dev;
1908c2ecf20Sopenharmony_ci	struct regmap *regmap;
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	unsigned int dl_rate;
1938c2ecf20Sopenharmony_ci	unsigned int ul_rate;
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci	int ana_gain[AUDIO_ANALOG_VOLUME_TYPE_MAX];
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	int hp_en_counter;
1988c2ecf20Sopenharmony_ci};
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_cistatic void set_hp_gain_zero(struct snd_soc_component *cmpnt)
2018c2ecf20Sopenharmony_ci{
2028c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON2,
2038c2ecf20Sopenharmony_ci			   0x1f << 7, 0x8 << 7);
2048c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON2,
2058c2ecf20Sopenharmony_ci			   0x1f << 0, 0x8 << 0);
2068c2ecf20Sopenharmony_ci}
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_cistatic unsigned int get_cap_reg_val(struct snd_soc_component *cmpnt,
2098c2ecf20Sopenharmony_ci				    unsigned int rate)
2108c2ecf20Sopenharmony_ci{
2118c2ecf20Sopenharmony_ci	switch (rate) {
2128c2ecf20Sopenharmony_ci	case 8000:
2138c2ecf20Sopenharmony_ci		return 0;
2148c2ecf20Sopenharmony_ci	case 16000:
2158c2ecf20Sopenharmony_ci		return 1;
2168c2ecf20Sopenharmony_ci	case 32000:
2178c2ecf20Sopenharmony_ci		return 2;
2188c2ecf20Sopenharmony_ci	case 48000:
2198c2ecf20Sopenharmony_ci		return 3;
2208c2ecf20Sopenharmony_ci	case 96000:
2218c2ecf20Sopenharmony_ci		return 4;
2228c2ecf20Sopenharmony_ci	case 192000:
2238c2ecf20Sopenharmony_ci		return 5;
2248c2ecf20Sopenharmony_ci	default:
2258c2ecf20Sopenharmony_ci		dev_warn(cmpnt->dev, "%s(), error rate %d, return 3",
2268c2ecf20Sopenharmony_ci			 __func__, rate);
2278c2ecf20Sopenharmony_ci		return 3;
2288c2ecf20Sopenharmony_ci	}
2298c2ecf20Sopenharmony_ci}
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_cistatic unsigned int get_play_reg_val(struct snd_soc_component *cmpnt,
2328c2ecf20Sopenharmony_ci				     unsigned int rate)
2338c2ecf20Sopenharmony_ci{
2348c2ecf20Sopenharmony_ci	switch (rate) {
2358c2ecf20Sopenharmony_ci	case 8000:
2368c2ecf20Sopenharmony_ci		return 0;
2378c2ecf20Sopenharmony_ci	case 11025:
2388c2ecf20Sopenharmony_ci		return 1;
2398c2ecf20Sopenharmony_ci	case 12000:
2408c2ecf20Sopenharmony_ci		return 2;
2418c2ecf20Sopenharmony_ci	case 16000:
2428c2ecf20Sopenharmony_ci		return 3;
2438c2ecf20Sopenharmony_ci	case 22050:
2448c2ecf20Sopenharmony_ci		return 4;
2458c2ecf20Sopenharmony_ci	case 24000:
2468c2ecf20Sopenharmony_ci		return 5;
2478c2ecf20Sopenharmony_ci	case 32000:
2488c2ecf20Sopenharmony_ci		return 6;
2498c2ecf20Sopenharmony_ci	case 44100:
2508c2ecf20Sopenharmony_ci		return 7;
2518c2ecf20Sopenharmony_ci	case 48000:
2528c2ecf20Sopenharmony_ci	case 96000:
2538c2ecf20Sopenharmony_ci	case 192000:
2548c2ecf20Sopenharmony_ci		return 8;
2558c2ecf20Sopenharmony_ci	default:
2568c2ecf20Sopenharmony_ci		dev_warn(cmpnt->dev, "%s(), error rate %d, return 8",
2578c2ecf20Sopenharmony_ci			 __func__, rate);
2588c2ecf20Sopenharmony_ci		return 8;
2598c2ecf20Sopenharmony_ci	}
2608c2ecf20Sopenharmony_ci}
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_cistatic int mt6351_codec_dai_hw_params(struct snd_pcm_substream *substream,
2638c2ecf20Sopenharmony_ci				      struct snd_pcm_hw_params *params,
2648c2ecf20Sopenharmony_ci				      struct snd_soc_dai *dai)
2658c2ecf20Sopenharmony_ci{
2668c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = dai->component;
2678c2ecf20Sopenharmony_ci	struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt);
2688c2ecf20Sopenharmony_ci	unsigned int rate = params_rate(params);
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), substream->stream %d, rate %d\n",
2718c2ecf20Sopenharmony_ci		__func__, substream->stream, rate);
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
2748c2ecf20Sopenharmony_ci		priv->dl_rate = rate;
2758c2ecf20Sopenharmony_ci	else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
2768c2ecf20Sopenharmony_ci		priv->ul_rate = rate;
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	return 0;
2798c2ecf20Sopenharmony_ci}
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops mt6351_codec_dai_ops = {
2828c2ecf20Sopenharmony_ci	.hw_params = mt6351_codec_dai_hw_params,
2838c2ecf20Sopenharmony_ci};
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci#define MT6351_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |\
2868c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE |\
2878c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |\
2888c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE |\
2898c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |\
2908c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE)
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver mt6351_dai_driver[] = {
2938c2ecf20Sopenharmony_ci	{
2948c2ecf20Sopenharmony_ci		.name = "mt6351-snd-codec-aif1",
2958c2ecf20Sopenharmony_ci		.playback = {
2968c2ecf20Sopenharmony_ci			.stream_name = "AIF1 Playback",
2978c2ecf20Sopenharmony_ci			.channels_min = 1,
2988c2ecf20Sopenharmony_ci			.channels_max = 2,
2998c2ecf20Sopenharmony_ci			.rates = SNDRV_PCM_RATE_8000_48000 |
3008c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_96000 |
3018c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_192000,
3028c2ecf20Sopenharmony_ci			.formats = MT6351_FORMATS,
3038c2ecf20Sopenharmony_ci		},
3048c2ecf20Sopenharmony_ci		.capture = {
3058c2ecf20Sopenharmony_ci			.stream_name = "AIF1 Capture",
3068c2ecf20Sopenharmony_ci			.channels_min = 1,
3078c2ecf20Sopenharmony_ci			.channels_max = 2,
3088c2ecf20Sopenharmony_ci			.rates = SNDRV_PCM_RATE_8000 |
3098c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_16000 |
3108c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_32000 |
3118c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_48000 |
3128c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_96000 |
3138c2ecf20Sopenharmony_ci				 SNDRV_PCM_RATE_192000,
3148c2ecf20Sopenharmony_ci			.formats = MT6351_FORMATS,
3158c2ecf20Sopenharmony_ci		},
3168c2ecf20Sopenharmony_ci		.ops = &mt6351_codec_dai_ops,
3178c2ecf20Sopenharmony_ci	},
3188c2ecf20Sopenharmony_ci};
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_cienum {
3218c2ecf20Sopenharmony_ci	HP_GAIN_SET_ZERO,
3228c2ecf20Sopenharmony_ci	HP_GAIN_RESTORE,
3238c2ecf20Sopenharmony_ci};
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_cistatic void hp_gain_ramp_set(struct snd_soc_component *cmpnt, int hp_gain_ctl)
3268c2ecf20Sopenharmony_ci{
3278c2ecf20Sopenharmony_ci	struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt);
3288c2ecf20Sopenharmony_ci	int idx, old_idx, offset, reg_idx;
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	if (hp_gain_ctl == HP_GAIN_SET_ZERO) {
3318c2ecf20Sopenharmony_ci		idx = 8;	/* 0dB */
3328c2ecf20Sopenharmony_ci		old_idx = priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL];
3338c2ecf20Sopenharmony_ci	} else {
3348c2ecf20Sopenharmony_ci		idx = priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL];
3358c2ecf20Sopenharmony_ci		old_idx = 8;	/* 0dB */
3368c2ecf20Sopenharmony_ci	}
3378c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), idx %d, old_idx %d\n",
3388c2ecf20Sopenharmony_ci		__func__, idx, old_idx);
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	if (idx > old_idx)
3418c2ecf20Sopenharmony_ci		offset = idx - old_idx;
3428c2ecf20Sopenharmony_ci	else
3438c2ecf20Sopenharmony_ci		offset = old_idx - idx;
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	reg_idx = old_idx;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	while (offset > 0) {
3488c2ecf20Sopenharmony_ci		reg_idx = idx > old_idx ? reg_idx + 1 : reg_idx - 1;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci		/* check valid range, and set value */
3518c2ecf20Sopenharmony_ci		if ((reg_idx >= 0 && reg_idx <= 0x12) || reg_idx == 0x1f) {
3528c2ecf20Sopenharmony_ci			regmap_update_bits(cmpnt->regmap,
3538c2ecf20Sopenharmony_ci					   MT6351_ZCD_CON2,
3548c2ecf20Sopenharmony_ci					   0xf9f,
3558c2ecf20Sopenharmony_ci					   (reg_idx << 7) | reg_idx);
3568c2ecf20Sopenharmony_ci			usleep_range(100, 120);
3578c2ecf20Sopenharmony_ci		}
3588c2ecf20Sopenharmony_ci		offset--;
3598c2ecf20Sopenharmony_ci	}
3608c2ecf20Sopenharmony_ci}
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_cistatic void hp_zcd_enable(struct snd_soc_component *cmpnt)
3638c2ecf20Sopenharmony_ci{
3648c2ecf20Sopenharmony_ci	/* Enable ZCD, for minimize pop noise */
3658c2ecf20Sopenharmony_ci	/* when adjust gain during HP buffer on */
3668c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x7 << 8, 0x1 << 8);
3678c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x1 << 7, 0x0 << 7);
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	/* timeout, 1=5ms, 0=30ms */
3708c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x1 << 6, 0x1 << 6);
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x3 << 4, 0x0 << 4);
3738c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x7 << 1, 0x5 << 1);
3748c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_ZCD_CON0, 0x1 << 0, 0x1 << 0);
3758c2ecf20Sopenharmony_ci}
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_cistatic void hp_zcd_disable(struct snd_soc_component *cmpnt)
3788c2ecf20Sopenharmony_ci{
3798c2ecf20Sopenharmony_ci	regmap_write(cmpnt->regmap, MT6351_ZCD_CON0, 0x0000);
3808c2ecf20Sopenharmony_ci}
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(playback_tlv, -1000, 100, 0);
3838c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(pga_tlv, 0, 600, 0);
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new mt6351_snd_controls[] = {
3868c2ecf20Sopenharmony_ci	/* dl pga gain */
3878c2ecf20Sopenharmony_ci	SOC_DOUBLE_TLV("Headphone Volume",
3888c2ecf20Sopenharmony_ci		       MT6351_ZCD_CON2, 0, 7, 0x12, 1,
3898c2ecf20Sopenharmony_ci		       playback_tlv),
3908c2ecf20Sopenharmony_ci	SOC_DOUBLE_TLV("Lineout Volume",
3918c2ecf20Sopenharmony_ci		       MT6351_ZCD_CON1, 0, 7, 0x12, 1,
3928c2ecf20Sopenharmony_ci		       playback_tlv),
3938c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("Handset Volume",
3948c2ecf20Sopenharmony_ci		       MT6351_ZCD_CON3, 0, 0x12, 1,
3958c2ecf20Sopenharmony_ci		       playback_tlv),
3968c2ecf20Sopenharmony_ci       /* ul pga gain */
3978c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_TLV("PGA Volume",
3988c2ecf20Sopenharmony_ci			 MT6351_AUDENC_ANA_CON0, MT6351_AUDENC_ANA_CON1,
3998c2ecf20Sopenharmony_ci			 8, 4, 0,
4008c2ecf20Sopenharmony_ci			 pga_tlv),
4018c2ecf20Sopenharmony_ci};
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci/* MUX */
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci/* LOL MUX */
4068c2ecf20Sopenharmony_cistatic const char *const lo_in_mux_map[] = {
4078c2ecf20Sopenharmony_ci	"Open", "Mute", "Playback", "Test Mode",
4088c2ecf20Sopenharmony_ci};
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_cistatic int lo_in_mux_map_value[] = {
4118c2ecf20Sopenharmony_ci	0x0, 0x1, 0x2, 0x3,
4128c2ecf20Sopenharmony_ci};
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(lo_in_mux_map_enum,
4158c2ecf20Sopenharmony_ci				  MT6351_AUDDEC_ANA_CON3,
4168c2ecf20Sopenharmony_ci				  RG_AUDLOLMUXINPUTSEL_VAUDP32_SFT,
4178c2ecf20Sopenharmony_ci				  RG_AUDLOLMUXINPUTSEL_VAUDP32_MASK,
4188c2ecf20Sopenharmony_ci				  lo_in_mux_map,
4198c2ecf20Sopenharmony_ci				  lo_in_mux_map_value);
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new lo_in_mux_control =
4228c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("In Select", lo_in_mux_map_enum);
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci/*HP MUX */
4258c2ecf20Sopenharmony_cistatic const char *const hp_in_mux_map[] = {
4268c2ecf20Sopenharmony_ci	"Open", "LoudSPK Playback", "Audio Playback", "Test Mode",
4278c2ecf20Sopenharmony_ci};
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_cistatic int hp_in_mux_map_value[] = {
4308c2ecf20Sopenharmony_ci	0x0, 0x1, 0x2, 0x3,
4318c2ecf20Sopenharmony_ci};
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(hpl_in_mux_map_enum,
4348c2ecf20Sopenharmony_ci				  MT6351_AUDDEC_ANA_CON0,
4358c2ecf20Sopenharmony_ci				  RG_AUDHPLMUXINPUTSEL_VAUDP32_SFT,
4368c2ecf20Sopenharmony_ci				  RG_AUDHPLMUXINPUTSEL_VAUDP32_MASK,
4378c2ecf20Sopenharmony_ci				  hp_in_mux_map,
4388c2ecf20Sopenharmony_ci				  hp_in_mux_map_value);
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hpl_in_mux_control =
4418c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("HPL Select", hpl_in_mux_map_enum);
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(hpr_in_mux_map_enum,
4448c2ecf20Sopenharmony_ci				  MT6351_AUDDEC_ANA_CON0,
4458c2ecf20Sopenharmony_ci				  RG_AUDHPRMUXINPUTSEL_VAUDP32_SFT,
4468c2ecf20Sopenharmony_ci				  RG_AUDHPRMUXINPUTSEL_VAUDP32_MASK,
4478c2ecf20Sopenharmony_ci				  hp_in_mux_map,
4488c2ecf20Sopenharmony_ci				  hp_in_mux_map_value);
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hpr_in_mux_control =
4518c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("HPR Select", hpr_in_mux_map_enum);
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci/* RCV MUX */
4548c2ecf20Sopenharmony_cistatic const char *const rcv_in_mux_map[] = {
4558c2ecf20Sopenharmony_ci	"Open", "Mute", "Voice Playback", "Test Mode",
4568c2ecf20Sopenharmony_ci};
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_cistatic int rcv_in_mux_map_value[] = {
4598c2ecf20Sopenharmony_ci	0x0, 0x1, 0x2, 0x3,
4608c2ecf20Sopenharmony_ci};
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(rcv_in_mux_map_enum,
4638c2ecf20Sopenharmony_ci				  MT6351_AUDDEC_ANA_CON0,
4648c2ecf20Sopenharmony_ci				  RG_AUDHSMUXINPUTSEL_VAUDP32_SFT,
4658c2ecf20Sopenharmony_ci				  RG_AUDHSMUXINPUTSEL_VAUDP32_MASK,
4668c2ecf20Sopenharmony_ci				  rcv_in_mux_map,
4678c2ecf20Sopenharmony_ci				  rcv_in_mux_map_value);
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rcv_in_mux_control =
4708c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("RCV Select", rcv_in_mux_map_enum);
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ci/* DAC In MUX */
4738c2ecf20Sopenharmony_cistatic const char *const dac_in_mux_map[] = {
4748c2ecf20Sopenharmony_ci	"Normal Path", "Sgen",
4758c2ecf20Sopenharmony_ci};
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_cistatic int dac_in_mux_map_value[] = {
4788c2ecf20Sopenharmony_ci	0x0, 0x1,
4798c2ecf20Sopenharmony_ci};
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(dac_in_mux_map_enum,
4828c2ecf20Sopenharmony_ci				  MT6351_AFE_TOP_CON0,
4838c2ecf20Sopenharmony_ci				  RG_DL_SINE_ON_SFT,
4848c2ecf20Sopenharmony_ci				  RG_DL_SINE_ON_MASK,
4858c2ecf20Sopenharmony_ci				  dac_in_mux_map,
4868c2ecf20Sopenharmony_ci				  dac_in_mux_map_value);
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new dac_in_mux_control =
4898c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("DAC Select", dac_in_mux_map_enum);
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci/* AIF Out MUX */
4928c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(aif_out_mux_map_enum,
4938c2ecf20Sopenharmony_ci				  MT6351_AFE_TOP_CON0,
4948c2ecf20Sopenharmony_ci				  RG_UL_SINE_ON_SFT,
4958c2ecf20Sopenharmony_ci				  RG_UL_SINE_ON_MASK,
4968c2ecf20Sopenharmony_ci				  dac_in_mux_map,
4978c2ecf20Sopenharmony_ci				  dac_in_mux_map_value);
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new aif_out_mux_control =
5008c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("AIF Out Select", aif_out_mux_map_enum);
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci/* ADC L MUX */
5038c2ecf20Sopenharmony_cistatic const char *const adc_left_mux_map[] = {
5048c2ecf20Sopenharmony_ci	"Idle", "AIN0", "Left Preamplifier", "Idle_1",
5058c2ecf20Sopenharmony_ci};
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_cistatic int adc_left_mux_map_value[] = {
5088c2ecf20Sopenharmony_ci	0x0, 0x1, 0x2, 0x3,
5098c2ecf20Sopenharmony_ci};
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(adc_left_mux_map_enum,
5128c2ecf20Sopenharmony_ci				  MT6351_AUDENC_ANA_CON0,
5138c2ecf20Sopenharmony_ci				  RG_AUDADCLINPUTSEL_SFT,
5148c2ecf20Sopenharmony_ci				  RG_AUDADCLINPUTSEL_MASK,
5158c2ecf20Sopenharmony_ci				  adc_left_mux_map,
5168c2ecf20Sopenharmony_ci				  adc_left_mux_map_value);
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new adc_left_mux_control =
5198c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("ADC L Select", adc_left_mux_map_enum);
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci/* ADC R MUX */
5228c2ecf20Sopenharmony_cistatic const char *const adc_right_mux_map[] = {
5238c2ecf20Sopenharmony_ci	"Idle", "AIN0", "Right Preamplifier", "Idle_1",
5248c2ecf20Sopenharmony_ci};
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_cistatic int adc_right_mux_map_value[] = {
5278c2ecf20Sopenharmony_ci	0x0, 0x1, 0x2, 0x3,
5288c2ecf20Sopenharmony_ci};
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(adc_right_mux_map_enum,
5318c2ecf20Sopenharmony_ci				  MT6351_AUDENC_ANA_CON1,
5328c2ecf20Sopenharmony_ci				  RG_AUDADCRINPUTSEL_SFT,
5338c2ecf20Sopenharmony_ci				  RG_AUDADCRINPUTSEL_MASK,
5348c2ecf20Sopenharmony_ci				  adc_right_mux_map,
5358c2ecf20Sopenharmony_ci				  adc_right_mux_map_value);
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new adc_right_mux_control =
5388c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("ADC R Select", adc_right_mux_map_enum);
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci/* PGA L MUX */
5418c2ecf20Sopenharmony_cistatic const char *const pga_left_mux_map[] = {
5428c2ecf20Sopenharmony_ci	"None", "AIN0", "AIN1", "AIN2",
5438c2ecf20Sopenharmony_ci};
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_cistatic int pga_left_mux_map_value[] = {
5468c2ecf20Sopenharmony_ci	0x0, 0x1, 0x2, 0x3,
5478c2ecf20Sopenharmony_ci};
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(pga_left_mux_map_enum,
5508c2ecf20Sopenharmony_ci				  MT6351_AUDENC_ANA_CON0,
5518c2ecf20Sopenharmony_ci				  RG_AUDPREAMPLINPUTSEL_SFT,
5528c2ecf20Sopenharmony_ci				  RG_AUDPREAMPLINPUTSEL_MASK,
5538c2ecf20Sopenharmony_ci				  pga_left_mux_map,
5548c2ecf20Sopenharmony_ci				  pga_left_mux_map_value);
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new pga_left_mux_control =
5578c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("PGA L Select", pga_left_mux_map_enum);
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_ci/* PGA R MUX */
5608c2ecf20Sopenharmony_cistatic const char *const pga_right_mux_map[] = {
5618c2ecf20Sopenharmony_ci	"None", "AIN0", "AIN3", "AIN2",
5628c2ecf20Sopenharmony_ci};
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_cistatic int pga_right_mux_map_value[] = {
5658c2ecf20Sopenharmony_ci	0x0, 0x1, 0x2, 0x3,
5668c2ecf20Sopenharmony_ci};
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(pga_right_mux_map_enum,
5698c2ecf20Sopenharmony_ci				  MT6351_AUDENC_ANA_CON1,
5708c2ecf20Sopenharmony_ci				  RG_AUDPREAMPRINPUTSEL_SFT,
5718c2ecf20Sopenharmony_ci				  RG_AUDPREAMPRINPUTSEL_MASK,
5728c2ecf20Sopenharmony_ci				  pga_right_mux_map,
5738c2ecf20Sopenharmony_ci				  pga_right_mux_map_value);
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new pga_right_mux_control =
5768c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("PGA R Select", pga_right_mux_map_enum);
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_cistatic int mt_reg_set_clr_event(struct snd_soc_dapm_widget *w,
5798c2ecf20Sopenharmony_ci				struct snd_kcontrol *kcontrol,
5808c2ecf20Sopenharmony_ci				int event)
5818c2ecf20Sopenharmony_ci{
5828c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_ci	switch (event) {
5858c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
5868c2ecf20Sopenharmony_ci		if (w->on_val) {
5878c2ecf20Sopenharmony_ci			/* SET REG */
5888c2ecf20Sopenharmony_ci			regmap_update_bits(cmpnt->regmap,
5898c2ecf20Sopenharmony_ci					   w->reg + REG_STRIDE,
5908c2ecf20Sopenharmony_ci					   0x1 << w->shift,
5918c2ecf20Sopenharmony_ci					   0x1 << w->shift);
5928c2ecf20Sopenharmony_ci		} else {
5938c2ecf20Sopenharmony_ci			/* CLR REG */
5948c2ecf20Sopenharmony_ci			regmap_update_bits(cmpnt->regmap,
5958c2ecf20Sopenharmony_ci					   w->reg + REG_STRIDE * 2,
5968c2ecf20Sopenharmony_ci					   0x1 << w->shift,
5978c2ecf20Sopenharmony_ci					   0x1 << w->shift);
5988c2ecf20Sopenharmony_ci		}
5998c2ecf20Sopenharmony_ci		break;
6008c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMD:
6018c2ecf20Sopenharmony_ci		if (w->off_val) {
6028c2ecf20Sopenharmony_ci			/* SET REG */
6038c2ecf20Sopenharmony_ci			regmap_update_bits(cmpnt->regmap,
6048c2ecf20Sopenharmony_ci					   w->reg + REG_STRIDE,
6058c2ecf20Sopenharmony_ci					   0x1 << w->shift,
6068c2ecf20Sopenharmony_ci					   0x1 << w->shift);
6078c2ecf20Sopenharmony_ci		} else {
6088c2ecf20Sopenharmony_ci			/* CLR REG */
6098c2ecf20Sopenharmony_ci			regmap_update_bits(cmpnt->regmap,
6108c2ecf20Sopenharmony_ci					   w->reg + REG_STRIDE * 2,
6118c2ecf20Sopenharmony_ci					   0x1 << w->shift,
6128c2ecf20Sopenharmony_ci					   0x1 << w->shift);
6138c2ecf20Sopenharmony_ci		}
6148c2ecf20Sopenharmony_ci		break;
6158c2ecf20Sopenharmony_ci	default:
6168c2ecf20Sopenharmony_ci		break;
6178c2ecf20Sopenharmony_ci	}
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ci	return 0;
6208c2ecf20Sopenharmony_ci}
6218c2ecf20Sopenharmony_ci
6228c2ecf20Sopenharmony_cistatic int mt_ncp_event(struct snd_soc_dapm_widget *w,
6238c2ecf20Sopenharmony_ci			struct snd_kcontrol *kcontrol,
6248c2ecf20Sopenharmony_ci			int event)
6258c2ecf20Sopenharmony_ci{
6268c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_ci	switch (event) {
6298c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
6308c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFE_NCP_CFG1,
6318c2ecf20Sopenharmony_ci				   0xffff, 0x1515);
6328c2ecf20Sopenharmony_ci		/* NCP: ck1 and ck2 clock frequecy adjust configure */
6338c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFE_NCP_CFG0,
6348c2ecf20Sopenharmony_ci				   0xfffe, 0x8C00);
6358c2ecf20Sopenharmony_ci		break;
6368c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
6378c2ecf20Sopenharmony_ci		usleep_range(250, 270);
6388c2ecf20Sopenharmony_ci		break;
6398c2ecf20Sopenharmony_ci	default:
6408c2ecf20Sopenharmony_ci		break;
6418c2ecf20Sopenharmony_ci	}
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci	return 0;
6448c2ecf20Sopenharmony_ci}
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_cistatic int mt_sgen_event(struct snd_soc_dapm_widget *w,
6478c2ecf20Sopenharmony_ci			 struct snd_kcontrol *kcontrol,
6488c2ecf20Sopenharmony_ci			 int event)
6498c2ecf20Sopenharmony_ci{
6508c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
6518c2ecf20Sopenharmony_ci
6528c2ecf20Sopenharmony_ci	switch (event) {
6538c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
6548c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFE_SGEN_CFG0,
6558c2ecf20Sopenharmony_ci				   0xffef, 0x0008);
6568c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFE_SGEN_CFG1,
6578c2ecf20Sopenharmony_ci				   0xffff, 0x0101);
6588c2ecf20Sopenharmony_ci		break;
6598c2ecf20Sopenharmony_ci	default:
6608c2ecf20Sopenharmony_ci		break;
6618c2ecf20Sopenharmony_ci	}
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_ci	return 0;
6648c2ecf20Sopenharmony_ci}
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_cistatic int mt_aif_in_event(struct snd_soc_dapm_widget *w,
6678c2ecf20Sopenharmony_ci			   struct snd_kcontrol *kcontrol,
6688c2ecf20Sopenharmony_ci			   int event)
6698c2ecf20Sopenharmony_ci{
6708c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
6718c2ecf20Sopenharmony_ci	struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt);
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event 0x%x, rate %d\n",
6748c2ecf20Sopenharmony_ci		__func__, event, priv->dl_rate);
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci	switch (event) {
6778c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
6788c2ecf20Sopenharmony_ci		/* sdm audio fifo clock power on */
6798c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON2,
6808c2ecf20Sopenharmony_ci				   0xffff, 0x0006);
6818c2ecf20Sopenharmony_ci		/* scrambler clock on enable */
6828c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON0,
6838c2ecf20Sopenharmony_ci				   0xffff, 0xC3A1);
6848c2ecf20Sopenharmony_ci		/* sdm power on */
6858c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON2,
6868c2ecf20Sopenharmony_ci				   0xffff, 0x0003);
6878c2ecf20Sopenharmony_ci		/* sdm fifo enable */
6888c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFUNC_AUD_CON2,
6898c2ecf20Sopenharmony_ci				   0xffff, 0x000B);
6908c2ecf20Sopenharmony_ci		/* set attenuation gain */
6918c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFE_DL_SDM_CON1,
6928c2ecf20Sopenharmony_ci				   0xffff, 0x001E);
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci		regmap_write(cmpnt->regmap, MT6351_AFE_PMIC_NEWIF_CFG0,
6958c2ecf20Sopenharmony_ci			     (get_play_reg_val(cmpnt, priv->dl_rate) << 12) |
6968c2ecf20Sopenharmony_ci			     0x330);
6978c2ecf20Sopenharmony_ci		regmap_write(cmpnt->regmap, MT6351_AFE_DL_SRC2_CON0_H,
6988c2ecf20Sopenharmony_ci			     (get_play_reg_val(cmpnt, priv->dl_rate) << 12) |
6998c2ecf20Sopenharmony_ci			     0x300);
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFE_PMIC_NEWIF_CFG2,
7028c2ecf20Sopenharmony_ci				   0x8000, 0x8000);
7038c2ecf20Sopenharmony_ci		break;
7048c2ecf20Sopenharmony_ci	default:
7058c2ecf20Sopenharmony_ci		break;
7068c2ecf20Sopenharmony_ci	}
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci	return 0;
7098c2ecf20Sopenharmony_ci}
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_cistatic int mt_hp_event(struct snd_soc_dapm_widget *w,
7128c2ecf20Sopenharmony_ci		       struct snd_kcontrol *kcontrol,
7138c2ecf20Sopenharmony_ci		       int event)
7148c2ecf20Sopenharmony_ci{
7158c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
7168c2ecf20Sopenharmony_ci	struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt);
7178c2ecf20Sopenharmony_ci	int reg;
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event 0x%x, hp_en_counter %d\n",
7208c2ecf20Sopenharmony_ci		__func__, event, priv->hp_en_counter);
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci	switch (event) {
7238c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
7248c2ecf20Sopenharmony_ci		priv->hp_en_counter++;
7258c2ecf20Sopenharmony_ci		if (priv->hp_en_counter > 1)
7268c2ecf20Sopenharmony_ci			break;	/* already enabled, do nothing */
7278c2ecf20Sopenharmony_ci		else if (priv->hp_en_counter <= 0)
7288c2ecf20Sopenharmony_ci			dev_err(priv->dev, "%s(), hp_en_counter %d <= 0\n",
7298c2ecf20Sopenharmony_ci				__func__,
7308c2ecf20Sopenharmony_ci				priv->hp_en_counter);
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci		hp_zcd_disable(cmpnt);
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_ci		/* from yoyo HQA script */
7358c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON6,
7368c2ecf20Sopenharmony_ci				   0x0700, 0x0700);
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_ci		/* save target gain to restore after hardware open complete */
7398c2ecf20Sopenharmony_ci		regmap_read(cmpnt->regmap, MT6351_ZCD_CON2, &reg);
7408c2ecf20Sopenharmony_ci		priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] = reg & 0x1f;
7418c2ecf20Sopenharmony_ci		priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] = (reg >> 7) & 0x1f;
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ci		/* Set HPR/HPL gain as minimum (~ -40dB) */
7448c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap,
7458c2ecf20Sopenharmony_ci				   MT6351_ZCD_CON2, 0xffff, 0x0F9F);
7468c2ecf20Sopenharmony_ci		/* Set HS gain as minimum (~ -40dB) */
7478c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap,
7488c2ecf20Sopenharmony_ci				   MT6351_ZCD_CON3, 0xffff, 0x001F);
7498c2ecf20Sopenharmony_ci		/* De_OSC of HP */
7508c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON2,
7518c2ecf20Sopenharmony_ci				   0x0001, 0x0001);
7528c2ecf20Sopenharmony_ci		/* enable output STBENH */
7538c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1,
7548c2ecf20Sopenharmony_ci				   0xffff, 0x2000);
7558c2ecf20Sopenharmony_ci		/* De_OSC of voice, enable output STBENH */
7568c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1,
7578c2ecf20Sopenharmony_ci				   0xffff, 0x2100);
7588c2ecf20Sopenharmony_ci		/* Enable voice driver */
7598c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON0,
7608c2ecf20Sopenharmony_ci				   0x0010, 0xE090);
7618c2ecf20Sopenharmony_ci		/* Enable pre-charge buffer  */
7628c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1,
7638c2ecf20Sopenharmony_ci				   0xffff, 0x2140);
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_ci		usleep_range(50, 60);
7668c2ecf20Sopenharmony_ci
7678c2ecf20Sopenharmony_ci		/* Apply digital DC compensation value to DAC */
7688c2ecf20Sopenharmony_ci		set_hp_gain_zero(cmpnt);
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ci		/* Enable HPR/HPL */
7718c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1,
7728c2ecf20Sopenharmony_ci				   0xffff, 0x2100);
7738c2ecf20Sopenharmony_ci		/* Disable pre-charge buffer */
7748c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON1,
7758c2ecf20Sopenharmony_ci				   0xffff, 0x2000);
7768c2ecf20Sopenharmony_ci		/* Disable De_OSC of voice */
7778c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON0,
7788c2ecf20Sopenharmony_ci				   0x0010, 0xF4EF);
7798c2ecf20Sopenharmony_ci		/* Disable voice buffer */
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ci		/* from yoyo HQ */
7828c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON6,
7838c2ecf20Sopenharmony_ci				   0x0700, 0x0300);
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci		/* Enable ZCD, for minimize pop noise */
7868c2ecf20Sopenharmony_ci		/* when adjust gain during HP buffer on */
7878c2ecf20Sopenharmony_ci		hp_zcd_enable(cmpnt);
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci		/* apply volume setting */
7908c2ecf20Sopenharmony_ci		hp_gain_ramp_set(cmpnt, HP_GAIN_RESTORE);
7918c2ecf20Sopenharmony_ci
7928c2ecf20Sopenharmony_ci		break;
7938c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMD:
7948c2ecf20Sopenharmony_ci		priv->hp_en_counter--;
7958c2ecf20Sopenharmony_ci		if (priv->hp_en_counter > 0)
7968c2ecf20Sopenharmony_ci			break;	/* still being used, don't close */
7978c2ecf20Sopenharmony_ci		else if (priv->hp_en_counter < 0)
7988c2ecf20Sopenharmony_ci			dev_err(priv->dev, "%s(), hp_en_counter %d <= 0\n",
7998c2ecf20Sopenharmony_ci				__func__,
8008c2ecf20Sopenharmony_ci				priv->hp_en_counter);
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ci		/* Disable AUD_ZCD */
8038c2ecf20Sopenharmony_ci		hp_zcd_disable(cmpnt);
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci		/* Set HPR/HPL gain as -1dB, step by step */
8068c2ecf20Sopenharmony_ci		hp_gain_ramp_set(cmpnt, HP_GAIN_SET_ZERO);
8078c2ecf20Sopenharmony_ci
8088c2ecf20Sopenharmony_ci		set_hp_gain_zero(cmpnt);
8098c2ecf20Sopenharmony_ci		break;
8108c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
8118c2ecf20Sopenharmony_ci		if (priv->hp_en_counter > 0)
8128c2ecf20Sopenharmony_ci			break;	/* still being used, don't close */
8138c2ecf20Sopenharmony_ci		else if (priv->hp_en_counter < 0)
8148c2ecf20Sopenharmony_ci			dev_err(priv->dev, "%s(), hp_en_counter %d <= 0\n",
8158c2ecf20Sopenharmony_ci				__func__,
8168c2ecf20Sopenharmony_ci				priv->hp_en_counter);
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ci		/* reset*/
8198c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap,
8208c2ecf20Sopenharmony_ci				   MT6351_AUDDEC_ANA_CON6,
8218c2ecf20Sopenharmony_ci				   0x0700,
8228c2ecf20Sopenharmony_ci				   0x0000);
8238c2ecf20Sopenharmony_ci		/* De_OSC of HP */
8248c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap,
8258c2ecf20Sopenharmony_ci				   MT6351_AUDDEC_ANA_CON2,
8268c2ecf20Sopenharmony_ci				   0x0001,
8278c2ecf20Sopenharmony_ci				   0x0000);
8288c2ecf20Sopenharmony_ci
8298c2ecf20Sopenharmony_ci		/* apply volume setting */
8308c2ecf20Sopenharmony_ci		hp_gain_ramp_set(cmpnt, HP_GAIN_RESTORE);
8318c2ecf20Sopenharmony_ci		break;
8328c2ecf20Sopenharmony_ci	default:
8338c2ecf20Sopenharmony_ci		break;
8348c2ecf20Sopenharmony_ci	}
8358c2ecf20Sopenharmony_ci
8368c2ecf20Sopenharmony_ci	return 0;
8378c2ecf20Sopenharmony_ci}
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_cistatic int mt_aif_out_event(struct snd_soc_dapm_widget *w,
8408c2ecf20Sopenharmony_ci			    struct snd_kcontrol *kcontrol,
8418c2ecf20Sopenharmony_ci			    int event)
8428c2ecf20Sopenharmony_ci{
8438c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
8448c2ecf20Sopenharmony_ci	struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt);
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), event 0x%x, rate %d\n",
8478c2ecf20Sopenharmony_ci		__func__, event, priv->ul_rate);
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_ci	switch (event) {
8508c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
8518c2ecf20Sopenharmony_ci		/* dcclk_div=11'b00100000011, dcclk_ref_ck_sel=2'b00 */
8528c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFE_DCCLK_CFG0,
8538c2ecf20Sopenharmony_ci				   0xffff, 0x2062);
8548c2ecf20Sopenharmony_ci		/* dcclk_pdn=1'b0 */
8558c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFE_DCCLK_CFG0,
8568c2ecf20Sopenharmony_ci				   0xffff, 0x2060);
8578c2ecf20Sopenharmony_ci		/* dcclk_gen_on=1'b1 */
8588c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFE_DCCLK_CFG0,
8598c2ecf20Sopenharmony_ci				   0xffff, 0x2061);
8608c2ecf20Sopenharmony_ci
8618c2ecf20Sopenharmony_ci		/* UL sample rate and mode configure */
8628c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AFE_UL_SRC_CON0_H,
8638c2ecf20Sopenharmony_ci				   0x000E,
8648c2ecf20Sopenharmony_ci				   get_cap_reg_val(cmpnt, priv->ul_rate) << 1);
8658c2ecf20Sopenharmony_ci
8668c2ecf20Sopenharmony_ci		/* fixed 260k path for 8/16/32/48 */
8678c2ecf20Sopenharmony_ci		if (priv->ul_rate <= 48000) {
8688c2ecf20Sopenharmony_ci			/* anc ul path src on */
8698c2ecf20Sopenharmony_ci			regmap_update_bits(cmpnt->regmap,
8708c2ecf20Sopenharmony_ci					   MT6351_AFE_HPANC_CFG0,
8718c2ecf20Sopenharmony_ci					   0x1 << 1,
8728c2ecf20Sopenharmony_ci					   0x1 << 1);
8738c2ecf20Sopenharmony_ci			/* ANC clk pdn release */
8748c2ecf20Sopenharmony_ci			regmap_update_bits(cmpnt->regmap,
8758c2ecf20Sopenharmony_ci					   MT6351_AFE_HPANC_CFG0,
8768c2ecf20Sopenharmony_ci					   0x1 << 0,
8778c2ecf20Sopenharmony_ci					   0x0 << 0);
8788c2ecf20Sopenharmony_ci		}
8798c2ecf20Sopenharmony_ci		break;
8808c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMD:
8818c2ecf20Sopenharmony_ci		/* fixed 260k path for 8/16/32/48 */
8828c2ecf20Sopenharmony_ci		if (priv->ul_rate <= 48000) {
8838c2ecf20Sopenharmony_ci			/* anc ul path src on */
8848c2ecf20Sopenharmony_ci			regmap_update_bits(cmpnt->regmap,
8858c2ecf20Sopenharmony_ci					   MT6351_AFE_HPANC_CFG0,
8868c2ecf20Sopenharmony_ci					   0x1 << 1,
8878c2ecf20Sopenharmony_ci					   0x0 << 1);
8888c2ecf20Sopenharmony_ci			/* ANC clk pdn release */
8898c2ecf20Sopenharmony_ci			regmap_update_bits(cmpnt->regmap,
8908c2ecf20Sopenharmony_ci					   MT6351_AFE_HPANC_CFG0,
8918c2ecf20Sopenharmony_ci					   0x1 << 0,
8928c2ecf20Sopenharmony_ci					   0x1 << 0);
8938c2ecf20Sopenharmony_ci		}
8948c2ecf20Sopenharmony_ci		break;
8958c2ecf20Sopenharmony_ci	default:
8968c2ecf20Sopenharmony_ci		break;
8978c2ecf20Sopenharmony_ci	}
8988c2ecf20Sopenharmony_ci
8998c2ecf20Sopenharmony_ci	return 0;
9008c2ecf20Sopenharmony_ci}
9018c2ecf20Sopenharmony_ci
9028c2ecf20Sopenharmony_cistatic int mt_adc_clkgen_event(struct snd_soc_dapm_widget *w,
9038c2ecf20Sopenharmony_ci			       struct snd_kcontrol *kcontrol,
9048c2ecf20Sopenharmony_ci			       int event)
9058c2ecf20Sopenharmony_ci{
9068c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
9078c2ecf20Sopenharmony_ci
9088c2ecf20Sopenharmony_ci	switch (event) {
9098c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
9108c2ecf20Sopenharmony_ci		/* Audio ADC clock gen. mode: 00_divided by 2 (Normal) */
9118c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON3,
9128c2ecf20Sopenharmony_ci				   0x3 << 4, 0x0);
9138c2ecf20Sopenharmony_ci		break;
9148c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
9158c2ecf20Sopenharmony_ci		/* ADC CLK from: 00_13MHz from CLKSQ (Default) */
9168c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON3,
9178c2ecf20Sopenharmony_ci				   0x3 << 2, 0x0);
9188c2ecf20Sopenharmony_ci		break;
9198c2ecf20Sopenharmony_ci	default:
9208c2ecf20Sopenharmony_ci		break;
9218c2ecf20Sopenharmony_ci	}
9228c2ecf20Sopenharmony_ci	return 0;
9238c2ecf20Sopenharmony_ci}
9248c2ecf20Sopenharmony_ci
9258c2ecf20Sopenharmony_cistatic int mt_pga_left_event(struct snd_soc_dapm_widget *w,
9268c2ecf20Sopenharmony_ci			     struct snd_kcontrol *kcontrol,
9278c2ecf20Sopenharmony_ci			     int event)
9288c2ecf20Sopenharmony_ci{
9298c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_ci	switch (event) {
9328c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
9338c2ecf20Sopenharmony_ci		/* Audio L PGA precharge on */
9348c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON0,
9358c2ecf20Sopenharmony_ci				   0x3 << RG_AUDPREAMPLDCPRECHARGE,
9368c2ecf20Sopenharmony_ci				   0x1 << RG_AUDPREAMPLDCPRECHARGE);
9378c2ecf20Sopenharmony_ci		/* Audio L PGA mode: 1_DCC */
9388c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON0,
9398c2ecf20Sopenharmony_ci				   0x3 << RG_AUDPREAMPLDCCEN,
9408c2ecf20Sopenharmony_ci				   0x1 << RG_AUDPREAMPLDCCEN);
9418c2ecf20Sopenharmony_ci		break;
9428c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
9438c2ecf20Sopenharmony_ci		usleep_range(100, 120);
9448c2ecf20Sopenharmony_ci		/* Audio L PGA precharge off */
9458c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON0,
9468c2ecf20Sopenharmony_ci				   0x3 << RG_AUDPREAMPLDCPRECHARGE,
9478c2ecf20Sopenharmony_ci				   0x0 << RG_AUDPREAMPLDCPRECHARGE);
9488c2ecf20Sopenharmony_ci		break;
9498c2ecf20Sopenharmony_ci	default:
9508c2ecf20Sopenharmony_ci		break;
9518c2ecf20Sopenharmony_ci	}
9528c2ecf20Sopenharmony_ci	return 0;
9538c2ecf20Sopenharmony_ci}
9548c2ecf20Sopenharmony_ci
9558c2ecf20Sopenharmony_cistatic int mt_pga_right_event(struct snd_soc_dapm_widget *w,
9568c2ecf20Sopenharmony_ci			      struct snd_kcontrol *kcontrol,
9578c2ecf20Sopenharmony_ci			      int event)
9588c2ecf20Sopenharmony_ci{
9598c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
9608c2ecf20Sopenharmony_ci
9618c2ecf20Sopenharmony_ci	switch (event) {
9628c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
9638c2ecf20Sopenharmony_ci		/* Audio R PGA precharge on */
9648c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON1,
9658c2ecf20Sopenharmony_ci				   0x3 << RG_AUDPREAMPRDCPRECHARGE,
9668c2ecf20Sopenharmony_ci				   0x1 << RG_AUDPREAMPRDCPRECHARGE);
9678c2ecf20Sopenharmony_ci		/* Audio R PGA mode: 1_DCC */
9688c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON1,
9698c2ecf20Sopenharmony_ci				   0x3 << RG_AUDPREAMPRDCCEN,
9708c2ecf20Sopenharmony_ci				   0x1 << RG_AUDPREAMPRDCCEN);
9718c2ecf20Sopenharmony_ci		break;
9728c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
9738c2ecf20Sopenharmony_ci		usleep_range(100, 120);
9748c2ecf20Sopenharmony_ci		/* Audio R PGA precharge off */
9758c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON1,
9768c2ecf20Sopenharmony_ci				   0x3 << RG_AUDPREAMPRDCPRECHARGE,
9778c2ecf20Sopenharmony_ci				   0x0 << RG_AUDPREAMPRDCPRECHARGE);
9788c2ecf20Sopenharmony_ci		break;
9798c2ecf20Sopenharmony_ci	default:
9808c2ecf20Sopenharmony_ci		break;
9818c2ecf20Sopenharmony_ci	}
9828c2ecf20Sopenharmony_ci	return 0;
9838c2ecf20Sopenharmony_ci}
9848c2ecf20Sopenharmony_ci
9858c2ecf20Sopenharmony_cistatic int mt_mic_bias_0_event(struct snd_soc_dapm_widget *w,
9868c2ecf20Sopenharmony_ci			       struct snd_kcontrol *kcontrol,
9878c2ecf20Sopenharmony_ci			       int event)
9888c2ecf20Sopenharmony_ci{
9898c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
9908c2ecf20Sopenharmony_ci
9918c2ecf20Sopenharmony_ci	switch (event) {
9928c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
9938c2ecf20Sopenharmony_ci		/* MIC Bias 0 LowPower: 0_Normal */
9948c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9,
9958c2ecf20Sopenharmony_ci				   0x3 << RG_AUDMICBIAS0LOWPEN, 0x0);
9968c2ecf20Sopenharmony_ci		/* MISBIAS0 = 1P9V */
9978c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9,
9988c2ecf20Sopenharmony_ci				   0x7 << RG_AUDMICBIAS0VREF,
9998c2ecf20Sopenharmony_ci				   0x2 << RG_AUDMICBIAS0VREF);
10008c2ecf20Sopenharmony_ci		break;
10018c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
10028c2ecf20Sopenharmony_ci		/* MISBIAS0 = 1P97 */
10038c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9,
10048c2ecf20Sopenharmony_ci				   0x7 << RG_AUDMICBIAS0VREF,
10058c2ecf20Sopenharmony_ci				   0x0 << RG_AUDMICBIAS0VREF);
10068c2ecf20Sopenharmony_ci		break;
10078c2ecf20Sopenharmony_ci	default:
10088c2ecf20Sopenharmony_ci		break;
10098c2ecf20Sopenharmony_ci	}
10108c2ecf20Sopenharmony_ci	return 0;
10118c2ecf20Sopenharmony_ci}
10128c2ecf20Sopenharmony_ci
10138c2ecf20Sopenharmony_cistatic int mt_mic_bias_1_event(struct snd_soc_dapm_widget *w,
10148c2ecf20Sopenharmony_ci			       struct snd_kcontrol *kcontrol,
10158c2ecf20Sopenharmony_ci			       int event)
10168c2ecf20Sopenharmony_ci{
10178c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
10188c2ecf20Sopenharmony_ci
10198c2ecf20Sopenharmony_ci	switch (event) {
10208c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
10218c2ecf20Sopenharmony_ci		/* MIC Bias 1 LowPower: 0_Normal */
10228c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON10,
10238c2ecf20Sopenharmony_ci				   0x3 << RG_AUDMICBIAS1LOWPEN, 0x0);
10248c2ecf20Sopenharmony_ci		/* MISBIAS1 = 2P7V */
10258c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON10,
10268c2ecf20Sopenharmony_ci				   0x7 << RG_AUDMICBIAS1VREF,
10278c2ecf20Sopenharmony_ci				   0x7 << RG_AUDMICBIAS1VREF);
10288c2ecf20Sopenharmony_ci		break;
10298c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
10308c2ecf20Sopenharmony_ci		/* MISBIAS1 = 1P7V */
10318c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON10,
10328c2ecf20Sopenharmony_ci				   0x7 << RG_AUDMICBIAS1VREF,
10338c2ecf20Sopenharmony_ci				   0x0 << RG_AUDMICBIAS1VREF);
10348c2ecf20Sopenharmony_ci		break;
10358c2ecf20Sopenharmony_ci	default:
10368c2ecf20Sopenharmony_ci		break;
10378c2ecf20Sopenharmony_ci	}
10388c2ecf20Sopenharmony_ci	return 0;
10398c2ecf20Sopenharmony_ci}
10408c2ecf20Sopenharmony_ci
10418c2ecf20Sopenharmony_cistatic int mt_mic_bias_2_event(struct snd_soc_dapm_widget *w,
10428c2ecf20Sopenharmony_ci			       struct snd_kcontrol *kcontrol,
10438c2ecf20Sopenharmony_ci			       int event)
10448c2ecf20Sopenharmony_ci{
10458c2ecf20Sopenharmony_ci	struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
10468c2ecf20Sopenharmony_ci
10478c2ecf20Sopenharmony_ci	switch (event) {
10488c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
10498c2ecf20Sopenharmony_ci		/* MIC Bias 2 LowPower: 0_Normal */
10508c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9,
10518c2ecf20Sopenharmony_ci				   0x3 << RG_AUDMICBIAS2LOWPEN, 0x0);
10528c2ecf20Sopenharmony_ci		/* MISBIAS2 = 1P9V */
10538c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9,
10548c2ecf20Sopenharmony_ci				   0x7 << RG_AUDMICBIAS2VREF,
10558c2ecf20Sopenharmony_ci				   0x2 << RG_AUDMICBIAS2VREF);
10568c2ecf20Sopenharmony_ci		break;
10578c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
10588c2ecf20Sopenharmony_ci		/* MISBIAS2 = 1P97 */
10598c2ecf20Sopenharmony_ci		regmap_update_bits(cmpnt->regmap, MT6351_AUDENC_ANA_CON9,
10608c2ecf20Sopenharmony_ci				   0x7 << RG_AUDMICBIAS2VREF,
10618c2ecf20Sopenharmony_ci				   0x0 << RG_AUDMICBIAS2VREF);
10628c2ecf20Sopenharmony_ci		break;
10638c2ecf20Sopenharmony_ci	default:
10648c2ecf20Sopenharmony_ci		break;
10658c2ecf20Sopenharmony_ci	}
10668c2ecf20Sopenharmony_ci	return 0;
10678c2ecf20Sopenharmony_ci}
10688c2ecf20Sopenharmony_ci
10698c2ecf20Sopenharmony_ci/* DAPM Widgets */
10708c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget mt6351_dapm_widgets[] = {
10718c2ecf20Sopenharmony_ci	/* Digital Clock */
10728c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("AUDIO_TOP_AFE_CTL", MT6351_AUDIO_TOP_CON0,
10738c2ecf20Sopenharmony_ci			    AUD_TOP_PDN_AFE_CTL_BIT, 1, NULL, 0),
10748c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("AUDIO_TOP_DAC_CTL", MT6351_AUDIO_TOP_CON0,
10758c2ecf20Sopenharmony_ci			    AUD_TOP_PDN_DAC_CTL_BIT, 1, NULL, 0),
10768c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("AUDIO_TOP_ADC_CTL", MT6351_AUDIO_TOP_CON0,
10778c2ecf20Sopenharmony_ci			    AUD_TOP_PDN_ADC_CTL_BIT, 1, NULL, 0),
10788c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("AUDIO_TOP_PWR_CLK", MT6351_AUDIO_TOP_CON0,
10798c2ecf20Sopenharmony_ci			    AUD_TOP_PWR_CLK_DIS_CTL_BIT, 1, NULL, 0),
10808c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("AUDIO_TOP_PDN_RESERVED", MT6351_AUDIO_TOP_CON0,
10818c2ecf20Sopenharmony_ci			    AUD_TOP_PDN_RESERVED_BIT, 1, NULL, 0),
10828c2ecf20Sopenharmony_ci
10838c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("NCP", MT6351_AFE_NCP_CFG0,
10848c2ecf20Sopenharmony_ci			    RG_NCP_ON_BIT, 0,
10858c2ecf20Sopenharmony_ci			    mt_ncp_event,
10868c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
10878c2ecf20Sopenharmony_ci
10888c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("DL Digital Clock", SND_SOC_NOPM,
10898c2ecf20Sopenharmony_ci			    0, 0, NULL, 0),
10908c2ecf20Sopenharmony_ci
10918c2ecf20Sopenharmony_ci	/* Global Supply*/
10928c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("AUDGLB", MT6351_AUDDEC_ANA_CON9,
10938c2ecf20Sopenharmony_ci			    RG_AUDGLB_PWRDN_VA32_BIT, 1, NULL, 0),
10948c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("CLKSQ Audio", MT6351_TOP_CLKSQ,
10958c2ecf20Sopenharmony_ci			    RG_CLKSQ_EN_AUD_BIT, 0,
10968c2ecf20Sopenharmony_ci			    mt_reg_set_clr_event,
10978c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
10988c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("ZCD13M_CK", MT6351_TOP_CKPDN_CON0,
10998c2ecf20Sopenharmony_ci			    RG_ZCD13M_CK_PDN_BIT, 1,
11008c2ecf20Sopenharmony_ci			    mt_reg_set_clr_event,
11018c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
11028c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("AUD_CK", MT6351_TOP_CKPDN_CON0,
11038c2ecf20Sopenharmony_ci			    RG_AUD_CK_PDN_BIT, 1,
11048c2ecf20Sopenharmony_ci			    mt_reg_set_clr_event,
11058c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
11068c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("AUDIF_CK", MT6351_TOP_CKPDN_CON0,
11078c2ecf20Sopenharmony_ci			    RG_AUDIF_CK_PDN_BIT, 1,
11088c2ecf20Sopenharmony_ci			    mt_reg_set_clr_event,
11098c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
11108c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("AUDNCP_CK", MT6351_TOP_CKPDN_CON0,
11118c2ecf20Sopenharmony_ci			    RG_AUDNCP_CK_PDN_BIT, 1,
11128c2ecf20Sopenharmony_ci			    mt_reg_set_clr_event,
11138c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
11148c2ecf20Sopenharmony_ci
11158c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("AFE_ON", MT6351_AFE_UL_DL_CON0, RG_AFE_ON_BIT, 0,
11168c2ecf20Sopenharmony_ci			    NULL, 0),
11178c2ecf20Sopenharmony_ci
11188c2ecf20Sopenharmony_ci	/* AIF Rx*/
11198c2ecf20Sopenharmony_ci	SND_SOC_DAPM_AIF_IN_E("AIF_RX", "AIF1 Playback", 0,
11208c2ecf20Sopenharmony_ci			      MT6351_AFE_DL_SRC2_CON0_L,
11218c2ecf20Sopenharmony_ci			      RG_DL_2_SRC_ON_TMP_CTL_PRE_BIT, 0,
11228c2ecf20Sopenharmony_ci			      mt_aif_in_event, SND_SOC_DAPM_PRE_PMU),
11238c2ecf20Sopenharmony_ci
11248c2ecf20Sopenharmony_ci	/* DL Supply */
11258c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("DL Power Supply", SND_SOC_NOPM,
11268c2ecf20Sopenharmony_ci			    0, 0, NULL, 0),
11278c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("NV Regulator", MT6351_AUDDEC_ANA_CON10,
11288c2ecf20Sopenharmony_ci			    RG_NVREG_EN_VAUDP32_BIT, 0, NULL, 0),
11298c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("AUD_CLK", MT6351_AUDDEC_ANA_CON9,
11308c2ecf20Sopenharmony_ci			    RG_RSTB_DECODER_VA32_BIT, 0, NULL, 0),
11318c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("IBIST", MT6351_AUDDEC_ANA_CON9,
11328c2ecf20Sopenharmony_ci			    RG_AUDIBIASPWRDN_VAUDP32_BIT, 1, NULL, 0),
11338c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("LDO", MT6351_AUDDEC_ANA_CON9,
11348c2ecf20Sopenharmony_ci			    RG_LCLDO_DEC_EN_VA32_BIT, 0, NULL, 0),
11358c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("LDO_REMOTE_SENSE", MT6351_AUDDEC_ANA_CON9,
11368c2ecf20Sopenharmony_ci			    RG_LCLDO_DEC_REMOTE_SENSE_VA18_BIT, 0, NULL, 0),
11378c2ecf20Sopenharmony_ci
11388c2ecf20Sopenharmony_ci	/* DAC */
11398c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("DAC In Mux", SND_SOC_NOPM, 0, 0, &dac_in_mux_control),
11408c2ecf20Sopenharmony_ci
11418c2ecf20Sopenharmony_ci	SND_SOC_DAPM_DAC("DACL", NULL, MT6351_AUDDEC_ANA_CON0,
11428c2ecf20Sopenharmony_ci			 RG_AUDDACLPWRUP_VAUDP32_BIT, 0),
11438c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("DACL_BIASGEN", MT6351_AUDDEC_ANA_CON0,
11448c2ecf20Sopenharmony_ci			    RG_AUD_DAC_PWL_UP_VA32_BIT, 0, NULL, 0),
11458c2ecf20Sopenharmony_ci
11468c2ecf20Sopenharmony_ci	SND_SOC_DAPM_DAC("DACR", NULL, MT6351_AUDDEC_ANA_CON0,
11478c2ecf20Sopenharmony_ci			 RG_AUDDACRPWRUP_VAUDP32_BIT, 0),
11488c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("DACR_BIASGEN", MT6351_AUDDEC_ANA_CON0,
11498c2ecf20Sopenharmony_ci			    RG_AUD_DAC_PWR_UP_VA32_BIT, 0, NULL, 0),
11508c2ecf20Sopenharmony_ci	/* LOL */
11518c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("LOL Mux", SND_SOC_NOPM, 0, 0, &lo_in_mux_control),
11528c2ecf20Sopenharmony_ci
11538c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("LO Stability Enh", MT6351_AUDDEC_ANA_CON3,
11548c2ecf20Sopenharmony_ci			    RG_LOOUTPUTSTBENH_VAUDP32_BIT, 0, NULL, 0),
11558c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("LOL Bias Gen", MT6351_AUDDEC_ANA_CON6,
11568c2ecf20Sopenharmony_ci			    RG_ABIDEC_RSVD0_VAUDP32_LOL_BIT, 0, NULL, 0),
11578c2ecf20Sopenharmony_ci
11588c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUT_DRV("LOL Buffer", MT6351_AUDDEC_ANA_CON3,
11598c2ecf20Sopenharmony_ci			     RG_AUDLOLPWRUP_VAUDP32_BIT, 0, NULL, 0),
11608c2ecf20Sopenharmony_ci
11618c2ecf20Sopenharmony_ci	/* Headphone */
11628c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("HPL Mux", SND_SOC_NOPM, 0, 0, &hpl_in_mux_control),
11638c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("HPR Mux", SND_SOC_NOPM, 0, 0, &hpr_in_mux_control),
11648c2ecf20Sopenharmony_ci
11658c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUT_DRV_E("HPL Power", MT6351_AUDDEC_ANA_CON0,
11668c2ecf20Sopenharmony_ci			       RG_AUDHPLPWRUP_VAUDP32_BIT, 0, NULL, 0,
11678c2ecf20Sopenharmony_ci			       mt_hp_event,
11688c2ecf20Sopenharmony_ci			       SND_SOC_DAPM_PRE_PMU |
11698c2ecf20Sopenharmony_ci			       SND_SOC_DAPM_PRE_PMD |
11708c2ecf20Sopenharmony_ci			       SND_SOC_DAPM_POST_PMD),
11718c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUT_DRV_E("HPR Power", MT6351_AUDDEC_ANA_CON0,
11728c2ecf20Sopenharmony_ci			       RG_AUDHPRPWRUP_VAUDP32_BIT, 0, NULL, 0,
11738c2ecf20Sopenharmony_ci			       mt_hp_event,
11748c2ecf20Sopenharmony_ci			       SND_SOC_DAPM_PRE_PMU |
11758c2ecf20Sopenharmony_ci			       SND_SOC_DAPM_PRE_PMD |
11768c2ecf20Sopenharmony_ci			       SND_SOC_DAPM_POST_PMD),
11778c2ecf20Sopenharmony_ci
11788c2ecf20Sopenharmony_ci	/* Receiver */
11798c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("RCV Mux", SND_SOC_NOPM, 0, 0, &rcv_in_mux_control),
11808c2ecf20Sopenharmony_ci
11818c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("RCV Stability Enh", MT6351_AUDDEC_ANA_CON1,
11828c2ecf20Sopenharmony_ci			    RG_HSOUTPUTSTBENH_VAUDP32_BIT, 0, NULL, 0),
11838c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("RCV Bias Gen", MT6351_AUDDEC_ANA_CON6,
11848c2ecf20Sopenharmony_ci			    RG_ABIDEC_RSVD0_VAUDP32_HS_BIT, 0, NULL, 0),
11858c2ecf20Sopenharmony_ci
11868c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUT_DRV("RCV Buffer", MT6351_AUDDEC_ANA_CON0,
11878c2ecf20Sopenharmony_ci			     RG_AUDHSPWRUP_VAUDP32_BIT, 0, NULL, 0),
11888c2ecf20Sopenharmony_ci
11898c2ecf20Sopenharmony_ci	/* Outputs */
11908c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("Receiver"),
11918c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("Headphone L"),
11928c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("Headphone R"),
11938c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("LINEOUT L"),
11948c2ecf20Sopenharmony_ci
11958c2ecf20Sopenharmony_ci	/* SGEN */
11968c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("SGEN DL Enable", MT6351_AFE_SGEN_CFG0,
11978c2ecf20Sopenharmony_ci			    SGEN_C_DAC_EN_CTL_BIT, 0, NULL, 0),
11988c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("SGEN MUTE", MT6351_AFE_SGEN_CFG0,
11998c2ecf20Sopenharmony_ci			    SGEN_C_MUTE_SW_CTL_BIT, 1,
12008c2ecf20Sopenharmony_ci			    mt_sgen_event, SND_SOC_DAPM_PRE_PMU),
12018c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("SGEN DL SRC", MT6351_AFE_DL_SRC2_CON0_L,
12028c2ecf20Sopenharmony_ci			    RG_DL_2_SRC_ON_TMP_CTL_PRE_BIT, 0, NULL, 0),
12038c2ecf20Sopenharmony_ci
12048c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("SGEN DL"),
12058c2ecf20Sopenharmony_ci
12068c2ecf20Sopenharmony_ci	/* Uplinks */
12078c2ecf20Sopenharmony_ci	SND_SOC_DAPM_AIF_OUT_E("AIF1TX", "AIF1 Capture", 0,
12088c2ecf20Sopenharmony_ci			       MT6351_AFE_UL_SRC_CON0_L,
12098c2ecf20Sopenharmony_ci			       UL_SRC_ON_TMP_CTL, 0,
12108c2ecf20Sopenharmony_ci			       mt_aif_out_event,
12118c2ecf20Sopenharmony_ci			       SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
12128c2ecf20Sopenharmony_ci
12138c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("VUSB33_LDO", SUPPLY_SUBSEQ_ENABLE,
12148c2ecf20Sopenharmony_ci			      MT6351_LDO_VUSB33_CON0, RG_VUSB33_EN, 0,
12158c2ecf20Sopenharmony_ci			      NULL, 0),
12168c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("VUSB33_LDO_CTRL", SUPPLY_SUBSEQ_SETTING,
12178c2ecf20Sopenharmony_ci			      MT6351_LDO_VUSB33_CON0, RG_VUSB33_ON_CTRL, 1,
12188c2ecf20Sopenharmony_ci			      NULL, 0),
12198c2ecf20Sopenharmony_ci
12208c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("VA18_LDO", SUPPLY_SUBSEQ_ENABLE,
12218c2ecf20Sopenharmony_ci			      MT6351_LDO_VA18_CON0, RG_VA18_EN, 0, NULL, 0),
12228c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("VA18_LDO_CTRL", SUPPLY_SUBSEQ_SETTING,
12238c2ecf20Sopenharmony_ci			      MT6351_LDO_VA18_CON0, RG_VA18_ON_CTRL, 1,
12248c2ecf20Sopenharmony_ci			      NULL, 0),
12258c2ecf20Sopenharmony_ci
12268c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("ADC CLKGEN", SUPPLY_SUBSEQ_ENABLE,
12278c2ecf20Sopenharmony_ci			      MT6351_AUDENC_ANA_CON3, RG_AUDADCCLKRSTB, 0,
12288c2ecf20Sopenharmony_ci			      mt_adc_clkgen_event,
12298c2ecf20Sopenharmony_ci			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
12308c2ecf20Sopenharmony_ci
12318c2ecf20Sopenharmony_ci	/* Uplinks MUX */
12328c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("AIF Out Mux", SND_SOC_NOPM, 0, 0,
12338c2ecf20Sopenharmony_ci			 &aif_out_mux_control),
12348c2ecf20Sopenharmony_ci
12358c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("ADC L Mux", SND_SOC_NOPM, 0, 0,
12368c2ecf20Sopenharmony_ci			 &adc_left_mux_control),
12378c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("ADC R Mux", SND_SOC_NOPM, 0, 0,
12388c2ecf20Sopenharmony_ci			 &adc_right_mux_control),
12398c2ecf20Sopenharmony_ci
12408c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("ADC L", NULL,
12418c2ecf20Sopenharmony_ci			 MT6351_AUDENC_ANA_CON0, RG_AUDADCLPWRUP, 0),
12428c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("ADC R", NULL,
12438c2ecf20Sopenharmony_ci			 MT6351_AUDENC_ANA_CON1, RG_AUDADCRPWRUP, 0),
12448c2ecf20Sopenharmony_ci
12458c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("PGA L Mux", SND_SOC_NOPM, 0, 0,
12468c2ecf20Sopenharmony_ci			 &pga_left_mux_control),
12478c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("PGA R Mux", SND_SOC_NOPM, 0, 0,
12488c2ecf20Sopenharmony_ci			 &pga_right_mux_control),
12498c2ecf20Sopenharmony_ci
12508c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA_E("PGA L", MT6351_AUDENC_ANA_CON0, RG_AUDPREAMPLON, 0,
12518c2ecf20Sopenharmony_ci			   NULL, 0,
12528c2ecf20Sopenharmony_ci			   mt_pga_left_event,
12538c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
12548c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA_E("PGA R", MT6351_AUDENC_ANA_CON1, RG_AUDPREAMPRON, 0,
12558c2ecf20Sopenharmony_ci			   NULL, 0,
12568c2ecf20Sopenharmony_ci			   mt_pga_right_event,
12578c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
12588c2ecf20Sopenharmony_ci
12598c2ecf20Sopenharmony_ci	/* main mic mic bias */
12608c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("Mic Bias 0", SUPPLY_SUBSEQ_MICBIAS,
12618c2ecf20Sopenharmony_ci			      MT6351_AUDENC_ANA_CON9, RG_AUDPWDBMICBIAS0, 0,
12628c2ecf20Sopenharmony_ci			      mt_mic_bias_0_event,
12638c2ecf20Sopenharmony_ci			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
12648c2ecf20Sopenharmony_ci	/* ref mic mic bias */
12658c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("Mic Bias 2", SUPPLY_SUBSEQ_MICBIAS,
12668c2ecf20Sopenharmony_ci			      MT6351_AUDENC_ANA_CON9, RG_AUDPWDBMICBIAS2, 0,
12678c2ecf20Sopenharmony_ci			      mt_mic_bias_2_event,
12688c2ecf20Sopenharmony_ci			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
12698c2ecf20Sopenharmony_ci	/* headset mic1/2 mic bias */
12708c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("Mic Bias 1", SUPPLY_SUBSEQ_MICBIAS,
12718c2ecf20Sopenharmony_ci			      MT6351_AUDENC_ANA_CON10, RG_AUDPWDBMICBIAS1, 0,
12728c2ecf20Sopenharmony_ci			      mt_mic_bias_1_event,
12738c2ecf20Sopenharmony_ci			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
12748c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY_S("Mic Bias 1 DCC pull high", SUPPLY_SUBSEQ_MICBIAS,
12758c2ecf20Sopenharmony_ci			      MT6351_AUDENC_ANA_CON10,
12768c2ecf20Sopenharmony_ci			      RG_AUDMICBIAS1DCSW1NEN, 0,
12778c2ecf20Sopenharmony_ci			      NULL, 0),
12788c2ecf20Sopenharmony_ci
12798c2ecf20Sopenharmony_ci	/* UL input */
12808c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AIN0"),
12818c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AIN1"),
12828c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AIN2"),
12838c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AIN3"),
12848c2ecf20Sopenharmony_ci};
12858c2ecf20Sopenharmony_ci
12868c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route mt6351_dapm_routes[] = {
12878c2ecf20Sopenharmony_ci	/* Capture */
12888c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AIF Out Mux"},
12898c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "VUSB33_LDO"},
12908c2ecf20Sopenharmony_ci	{"VUSB33_LDO", NULL, "VUSB33_LDO_CTRL"},
12918c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "VA18_LDO"},
12928c2ecf20Sopenharmony_ci	{"VA18_LDO", NULL, "VA18_LDO_CTRL"},
12938c2ecf20Sopenharmony_ci
12948c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDGLB"},
12958c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "CLKSQ Audio"},
12968c2ecf20Sopenharmony_ci
12978c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AFE_ON"},
12988c2ecf20Sopenharmony_ci
12998c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDIO_TOP_AFE_CTL"},
13008c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDIO_TOP_ADC_CTL"},
13018c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDIO_TOP_PWR_CLK"},
13028c2ecf20Sopenharmony_ci	{"AIF1TX", NULL, "AUDIO_TOP_PDN_RESERVED"},
13038c2ecf20Sopenharmony_ci
13048c2ecf20Sopenharmony_ci	{"AIF Out Mux", "Normal Path", "ADC L"},
13058c2ecf20Sopenharmony_ci	{"AIF Out Mux", "Normal Path", "ADC R"},
13068c2ecf20Sopenharmony_ci
13078c2ecf20Sopenharmony_ci	{"ADC L", NULL, "ADC L Mux"},
13088c2ecf20Sopenharmony_ci	{"ADC L", NULL, "AUD_CK"},
13098c2ecf20Sopenharmony_ci	{"ADC L", NULL, "AUDIF_CK"},
13108c2ecf20Sopenharmony_ci	{"ADC L", NULL, "ADC CLKGEN"},
13118c2ecf20Sopenharmony_ci	{"ADC R", NULL, "ADC R Mux"},
13128c2ecf20Sopenharmony_ci	{"ADC R", NULL, "AUD_CK"},
13138c2ecf20Sopenharmony_ci	{"ADC R", NULL, "AUDIF_CK"},
13148c2ecf20Sopenharmony_ci	{"ADC R", NULL, "ADC CLKGEN"},
13158c2ecf20Sopenharmony_ci
13168c2ecf20Sopenharmony_ci	{"ADC L Mux", "AIN0", "AIN0"},
13178c2ecf20Sopenharmony_ci	{"ADC L Mux", "Left Preamplifier", "PGA L"},
13188c2ecf20Sopenharmony_ci
13198c2ecf20Sopenharmony_ci	{"ADC R Mux", "AIN0", "AIN0"},
13208c2ecf20Sopenharmony_ci	{"ADC R Mux", "Right Preamplifier", "PGA R"},
13218c2ecf20Sopenharmony_ci
13228c2ecf20Sopenharmony_ci	{"PGA L", NULL, "PGA L Mux"},
13238c2ecf20Sopenharmony_ci	{"PGA R", NULL, "PGA R Mux"},
13248c2ecf20Sopenharmony_ci
13258c2ecf20Sopenharmony_ci	{"PGA L Mux", "AIN0", "AIN0"},
13268c2ecf20Sopenharmony_ci	{"PGA L Mux", "AIN1", "AIN1"},
13278c2ecf20Sopenharmony_ci	{"PGA L Mux", "AIN2", "AIN2"},
13288c2ecf20Sopenharmony_ci
13298c2ecf20Sopenharmony_ci	{"PGA R Mux", "AIN0", "AIN0"},
13308c2ecf20Sopenharmony_ci	{"PGA R Mux", "AIN3", "AIN3"},
13318c2ecf20Sopenharmony_ci	{"PGA R Mux", "AIN2", "AIN2"},
13328c2ecf20Sopenharmony_ci
13338c2ecf20Sopenharmony_ci	{"AIN0", NULL, "Mic Bias 0"},
13348c2ecf20Sopenharmony_ci	{"AIN2", NULL, "Mic Bias 2"},
13358c2ecf20Sopenharmony_ci
13368c2ecf20Sopenharmony_ci	{"AIN1", NULL, "Mic Bias 1"},
13378c2ecf20Sopenharmony_ci	{"AIN1", NULL, "Mic Bias 1 DCC pull high"},
13388c2ecf20Sopenharmony_ci
13398c2ecf20Sopenharmony_ci	/* DL Supply */
13408c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "AUDGLB"},
13418c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "CLKSQ Audio"},
13428c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "ZCD13M_CK"},
13438c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "AUD_CK"},
13448c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "AUDIF_CK"},
13458c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "AUDNCP_CK"},
13468c2ecf20Sopenharmony_ci
13478c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "NV Regulator"},
13488c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "AUD_CLK"},
13498c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "IBIST"},
13508c2ecf20Sopenharmony_ci	{"DL Power Supply", NULL, "LDO"},
13518c2ecf20Sopenharmony_ci	{"LDO", NULL, "LDO_REMOTE_SENSE"},
13528c2ecf20Sopenharmony_ci
13538c2ecf20Sopenharmony_ci	/* DL Digital Supply */
13548c2ecf20Sopenharmony_ci	{"DL Digital Clock", NULL, "AUDIO_TOP_AFE_CTL"},
13558c2ecf20Sopenharmony_ci	{"DL Digital Clock", NULL, "AUDIO_TOP_DAC_CTL"},
13568c2ecf20Sopenharmony_ci	{"DL Digital Clock", NULL, "AUDIO_TOP_PWR_CLK"},
13578c2ecf20Sopenharmony_ci	{"DL Digital Clock", NULL, "AUDIO_TOP_PDN_RESERVED"},
13588c2ecf20Sopenharmony_ci	{"DL Digital Clock", NULL, "NCP"},
13598c2ecf20Sopenharmony_ci	{"DL Digital Clock", NULL, "AFE_ON"},
13608c2ecf20Sopenharmony_ci
13618c2ecf20Sopenharmony_ci	{"AIF_RX", NULL, "DL Digital Clock"},
13628c2ecf20Sopenharmony_ci
13638c2ecf20Sopenharmony_ci	/* DL Path */
13648c2ecf20Sopenharmony_ci	{"DAC In Mux", "Normal Path", "AIF_RX"},
13658c2ecf20Sopenharmony_ci
13668c2ecf20Sopenharmony_ci	{"DAC In Mux", "Sgen", "SGEN DL"},
13678c2ecf20Sopenharmony_ci	{"SGEN DL", NULL, "SGEN DL SRC"},
13688c2ecf20Sopenharmony_ci	{"SGEN DL", NULL, "SGEN MUTE"},
13698c2ecf20Sopenharmony_ci	{"SGEN DL", NULL, "SGEN DL Enable"},
13708c2ecf20Sopenharmony_ci	{"SGEN DL", NULL, "DL Digital Clock"},
13718c2ecf20Sopenharmony_ci
13728c2ecf20Sopenharmony_ci	{"DACL", NULL, "DAC In Mux"},
13738c2ecf20Sopenharmony_ci	{"DACL", NULL, "DL Power Supply"},
13748c2ecf20Sopenharmony_ci	{"DACL", NULL, "DACL_BIASGEN"},
13758c2ecf20Sopenharmony_ci
13768c2ecf20Sopenharmony_ci	{"DACR", NULL, "DAC In Mux"},
13778c2ecf20Sopenharmony_ci	{"DACR", NULL, "DL Power Supply"},
13788c2ecf20Sopenharmony_ci	{"DACR", NULL, "DACR_BIASGEN"},
13798c2ecf20Sopenharmony_ci
13808c2ecf20Sopenharmony_ci	{"LOL Mux", "Playback", "DACL"},
13818c2ecf20Sopenharmony_ci
13828c2ecf20Sopenharmony_ci	{"LOL Buffer", NULL, "LOL Mux"},
13838c2ecf20Sopenharmony_ci	{"LOL Buffer", NULL, "LO Stability Enh"},
13848c2ecf20Sopenharmony_ci	{"LOL Buffer", NULL, "LOL Bias Gen"},
13858c2ecf20Sopenharmony_ci
13868c2ecf20Sopenharmony_ci	{"LINEOUT L", NULL, "LOL Buffer"},
13878c2ecf20Sopenharmony_ci
13888c2ecf20Sopenharmony_ci	/* Headphone Path */
13898c2ecf20Sopenharmony_ci	{"HPL Mux", "Audio Playback", "DACL"},
13908c2ecf20Sopenharmony_ci	{"HPR Mux", "Audio Playback", "DACR"},
13918c2ecf20Sopenharmony_ci
13928c2ecf20Sopenharmony_ci	{"HPL Mux", "LoudSPK Playback", "DACL"},
13938c2ecf20Sopenharmony_ci	{"HPR Mux", "LoudSPK Playback", "DACR"},
13948c2ecf20Sopenharmony_ci
13958c2ecf20Sopenharmony_ci	{"HPL Power", NULL, "HPL Mux"},
13968c2ecf20Sopenharmony_ci	{"HPR Power", NULL, "HPR Mux"},
13978c2ecf20Sopenharmony_ci
13988c2ecf20Sopenharmony_ci	{"Headphone L", NULL, "HPL Power"},
13998c2ecf20Sopenharmony_ci	{"Headphone R", NULL, "HPR Power"},
14008c2ecf20Sopenharmony_ci
14018c2ecf20Sopenharmony_ci	/* Receiver Path */
14028c2ecf20Sopenharmony_ci	{"RCV Mux", "Voice Playback", "DACL"},
14038c2ecf20Sopenharmony_ci
14048c2ecf20Sopenharmony_ci	{"RCV Buffer", NULL, "RCV Mux"},
14058c2ecf20Sopenharmony_ci	{"RCV Buffer", NULL, "RCV Stability Enh"},
14068c2ecf20Sopenharmony_ci	{"RCV Buffer", NULL, "RCV Bias Gen"},
14078c2ecf20Sopenharmony_ci
14088c2ecf20Sopenharmony_ci	{"Receiver", NULL, "RCV Buffer"},
14098c2ecf20Sopenharmony_ci};
14108c2ecf20Sopenharmony_ci
14118c2ecf20Sopenharmony_cistatic int mt6351_codec_init_reg(struct snd_soc_component *cmpnt)
14128c2ecf20Sopenharmony_ci{
14138c2ecf20Sopenharmony_ci	/* Disable CLKSQ 26MHz */
14148c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_TOP_CLKSQ, 0x0001, 0x0);
14158c2ecf20Sopenharmony_ci	/* disable AUDGLB */
14168c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON9,
14178c2ecf20Sopenharmony_ci			   0x1000, 0x1000);
14188c2ecf20Sopenharmony_ci	/* Turn off AUDNCP_CLKDIV engine clock,Turn off AUD 26M */
14198c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_TOP_CKPDN_CON0_SET,
14208c2ecf20Sopenharmony_ci			   0x3800, 0x3800);
14218c2ecf20Sopenharmony_ci	/* Disable HeadphoneL/HeadphoneR/voice short circuit protection */
14228c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON0,
14238c2ecf20Sopenharmony_ci			   0xe000, 0xe000);
14248c2ecf20Sopenharmony_ci	/* [5] = 1, disable LO buffer left short circuit protection */
14258c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_AUDDEC_ANA_CON3,
14268c2ecf20Sopenharmony_ci			   0x20, 0x20);
14278c2ecf20Sopenharmony_ci	/* Reverse the PMIC clock*/
14288c2ecf20Sopenharmony_ci	regmap_update_bits(cmpnt->regmap, MT6351_AFE_PMIC_NEWIF_CFG2,
14298c2ecf20Sopenharmony_ci			   0x8000, 0x8000);
14308c2ecf20Sopenharmony_ci	return 0;
14318c2ecf20Sopenharmony_ci}
14328c2ecf20Sopenharmony_ci
14338c2ecf20Sopenharmony_cistatic int mt6351_codec_probe(struct snd_soc_component *cmpnt)
14348c2ecf20Sopenharmony_ci{
14358c2ecf20Sopenharmony_ci	struct mt6351_priv *priv = snd_soc_component_get_drvdata(cmpnt);
14368c2ecf20Sopenharmony_ci
14378c2ecf20Sopenharmony_ci	snd_soc_component_init_regmap(cmpnt, priv->regmap);
14388c2ecf20Sopenharmony_ci
14398c2ecf20Sopenharmony_ci	mt6351_codec_init_reg(cmpnt);
14408c2ecf20Sopenharmony_ci	return 0;
14418c2ecf20Sopenharmony_ci}
14428c2ecf20Sopenharmony_ci
14438c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver mt6351_soc_component_driver = {
14448c2ecf20Sopenharmony_ci	.probe = mt6351_codec_probe,
14458c2ecf20Sopenharmony_ci	.controls = mt6351_snd_controls,
14468c2ecf20Sopenharmony_ci	.num_controls = ARRAY_SIZE(mt6351_snd_controls),
14478c2ecf20Sopenharmony_ci	.dapm_widgets = mt6351_dapm_widgets,
14488c2ecf20Sopenharmony_ci	.num_dapm_widgets = ARRAY_SIZE(mt6351_dapm_widgets),
14498c2ecf20Sopenharmony_ci	.dapm_routes = mt6351_dapm_routes,
14508c2ecf20Sopenharmony_ci	.num_dapm_routes = ARRAY_SIZE(mt6351_dapm_routes),
14518c2ecf20Sopenharmony_ci};
14528c2ecf20Sopenharmony_ci
14538c2ecf20Sopenharmony_cistatic int mt6351_codec_driver_probe(struct platform_device *pdev)
14548c2ecf20Sopenharmony_ci{
14558c2ecf20Sopenharmony_ci	struct mt6351_priv *priv;
14568c2ecf20Sopenharmony_ci
14578c2ecf20Sopenharmony_ci	priv = devm_kzalloc(&pdev->dev,
14588c2ecf20Sopenharmony_ci			    sizeof(struct mt6351_priv),
14598c2ecf20Sopenharmony_ci			    GFP_KERNEL);
14608c2ecf20Sopenharmony_ci	if (!priv)
14618c2ecf20Sopenharmony_ci		return -ENOMEM;
14628c2ecf20Sopenharmony_ci
14638c2ecf20Sopenharmony_ci	dev_set_drvdata(&pdev->dev, priv);
14648c2ecf20Sopenharmony_ci
14658c2ecf20Sopenharmony_ci	priv->dev = &pdev->dev;
14668c2ecf20Sopenharmony_ci
14678c2ecf20Sopenharmony_ci	priv->regmap = dev_get_regmap(pdev->dev.parent, NULL);
14688c2ecf20Sopenharmony_ci	if (!priv->regmap)
14698c2ecf20Sopenharmony_ci		return -ENODEV;
14708c2ecf20Sopenharmony_ci
14718c2ecf20Sopenharmony_ci	dev_dbg(priv->dev, "%s(), dev name %s\n",
14728c2ecf20Sopenharmony_ci		__func__, dev_name(&pdev->dev));
14738c2ecf20Sopenharmony_ci
14748c2ecf20Sopenharmony_ci	return devm_snd_soc_register_component(&pdev->dev,
14758c2ecf20Sopenharmony_ci					       &mt6351_soc_component_driver,
14768c2ecf20Sopenharmony_ci					       mt6351_dai_driver,
14778c2ecf20Sopenharmony_ci					       ARRAY_SIZE(mt6351_dai_driver));
14788c2ecf20Sopenharmony_ci}
14798c2ecf20Sopenharmony_ci
14808c2ecf20Sopenharmony_cistatic const struct of_device_id mt6351_of_match[] = {
14818c2ecf20Sopenharmony_ci	{.compatible = "mediatek,mt6351-sound",},
14828c2ecf20Sopenharmony_ci	{}
14838c2ecf20Sopenharmony_ci};
14848c2ecf20Sopenharmony_ci
14858c2ecf20Sopenharmony_cistatic struct platform_driver mt6351_codec_driver = {
14868c2ecf20Sopenharmony_ci	.driver = {
14878c2ecf20Sopenharmony_ci		.name = "mt6351-sound",
14888c2ecf20Sopenharmony_ci		.of_match_table = mt6351_of_match,
14898c2ecf20Sopenharmony_ci	},
14908c2ecf20Sopenharmony_ci	.probe = mt6351_codec_driver_probe,
14918c2ecf20Sopenharmony_ci};
14928c2ecf20Sopenharmony_ci
14938c2ecf20Sopenharmony_cimodule_platform_driver(mt6351_codec_driver)
14948c2ecf20Sopenharmony_ci
14958c2ecf20Sopenharmony_ci/* Module information */
14968c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("MT6351 ALSA SoC codec driver");
14978c2ecf20Sopenharmony_ciMODULE_AUTHOR("KaiChieh Chuang <kaichieh.chuang@mediatek.com>");
14988c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
1499