18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * rt5631.c  --  RT5631 ALSA Soc Audio driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2011 Realtek Microelectronics
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: flove <flove@realtek.com>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Based on WM8753.c
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#include <linux/module.h>
128c2ecf20Sopenharmony_ci#include <linux/moduleparam.h>
138c2ecf20Sopenharmony_ci#include <linux/init.h>
148c2ecf20Sopenharmony_ci#include <linux/delay.h>
158c2ecf20Sopenharmony_ci#include <linux/pm.h>
168c2ecf20Sopenharmony_ci#include <linux/i2c.h>
178c2ecf20Sopenharmony_ci#include <linux/regmap.h>
188c2ecf20Sopenharmony_ci#include <sound/core.h>
198c2ecf20Sopenharmony_ci#include <sound/pcm.h>
208c2ecf20Sopenharmony_ci#include <sound/pcm_params.h>
218c2ecf20Sopenharmony_ci#include <sound/soc.h>
228c2ecf20Sopenharmony_ci#include <sound/soc-dapm.h>
238c2ecf20Sopenharmony_ci#include <sound/initval.h>
248c2ecf20Sopenharmony_ci#include <sound/tlv.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include "rt5631.h"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistruct rt5631_priv {
298c2ecf20Sopenharmony_ci	struct regmap *regmap;
308c2ecf20Sopenharmony_ci	int codec_version;
318c2ecf20Sopenharmony_ci	int master;
328c2ecf20Sopenharmony_ci	int sysclk;
338c2ecf20Sopenharmony_ci	int rx_rate;
348c2ecf20Sopenharmony_ci	int bclk_rate;
358c2ecf20Sopenharmony_ci	int dmic_used_flag;
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistatic const struct reg_default rt5631_reg[] = {
398c2ecf20Sopenharmony_ci	{ RT5631_SPK_OUT_VOL, 0x8888 },
408c2ecf20Sopenharmony_ci	{ RT5631_HP_OUT_VOL, 0x8080 },
418c2ecf20Sopenharmony_ci	{ RT5631_MONO_AXO_1_2_VOL, 0xa080 },
428c2ecf20Sopenharmony_ci	{ RT5631_AUX_IN_VOL, 0x0808 },
438c2ecf20Sopenharmony_ci	{ RT5631_ADC_REC_MIXER, 0xf0f0 },
448c2ecf20Sopenharmony_ci	{ RT5631_VDAC_DIG_VOL, 0x0010 },
458c2ecf20Sopenharmony_ci	{ RT5631_OUTMIXER_L_CTRL, 0xffc0 },
468c2ecf20Sopenharmony_ci	{ RT5631_OUTMIXER_R_CTRL, 0xffc0 },
478c2ecf20Sopenharmony_ci	{ RT5631_AXO1MIXER_CTRL, 0x88c0 },
488c2ecf20Sopenharmony_ci	{ RT5631_AXO2MIXER_CTRL, 0x88c0 },
498c2ecf20Sopenharmony_ci	{ RT5631_DIG_MIC_CTRL, 0x3000 },
508c2ecf20Sopenharmony_ci	{ RT5631_MONO_INPUT_VOL, 0x8808 },
518c2ecf20Sopenharmony_ci	{ RT5631_SPK_MIXER_CTRL, 0xf8f8 },
528c2ecf20Sopenharmony_ci	{ RT5631_SPK_MONO_OUT_CTRL, 0xfc00 },
538c2ecf20Sopenharmony_ci	{ RT5631_SPK_MONO_HP_OUT_CTRL, 0x4440 },
548c2ecf20Sopenharmony_ci	{ RT5631_SDP_CTRL, 0x8000 },
558c2ecf20Sopenharmony_ci	{ RT5631_MONO_SDP_CTRL, 0x8000 },
568c2ecf20Sopenharmony_ci	{ RT5631_STEREO_AD_DA_CLK_CTRL, 0x2010 },
578c2ecf20Sopenharmony_ci	{ RT5631_GEN_PUR_CTRL_REG, 0x0e00 },
588c2ecf20Sopenharmony_ci	{ RT5631_INT_ST_IRQ_CTRL_2, 0x071a },
598c2ecf20Sopenharmony_ci	{ RT5631_MISC_CTRL, 0x2040 },
608c2ecf20Sopenharmony_ci	{ RT5631_DEPOP_FUN_CTRL_2, 0x8000 },
618c2ecf20Sopenharmony_ci	{ RT5631_SOFT_VOL_CTRL, 0x07e0 },
628c2ecf20Sopenharmony_ci	{ RT5631_ALC_CTRL_1, 0x0206 },
638c2ecf20Sopenharmony_ci	{ RT5631_ALC_CTRL_3, 0x2000 },
648c2ecf20Sopenharmony_ci	{ RT5631_PSEUDO_SPATL_CTRL, 0x0553 },
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/*
688c2ecf20Sopenharmony_ci * rt5631_write_index - write index register of 2nd layer
698c2ecf20Sopenharmony_ci */
708c2ecf20Sopenharmony_cistatic void rt5631_write_index(struct snd_soc_component *component,
718c2ecf20Sopenharmony_ci		unsigned int reg, unsigned int value)
728c2ecf20Sopenharmony_ci{
738c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INDEX_ADD, reg);
748c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INDEX_DATA, value);
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/*
788c2ecf20Sopenharmony_ci * rt5631_read_index - read index register of 2nd layer
798c2ecf20Sopenharmony_ci */
808c2ecf20Sopenharmony_cistatic unsigned int rt5631_read_index(struct snd_soc_component *component,
818c2ecf20Sopenharmony_ci				unsigned int reg)
828c2ecf20Sopenharmony_ci{
838c2ecf20Sopenharmony_ci	unsigned int value;
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INDEX_ADD, reg);
868c2ecf20Sopenharmony_ci	value = snd_soc_component_read(component, RT5631_INDEX_DATA);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	return value;
898c2ecf20Sopenharmony_ci}
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cistatic int rt5631_reset(struct snd_soc_component *component)
928c2ecf20Sopenharmony_ci{
938c2ecf20Sopenharmony_ci	return snd_soc_component_write(component, RT5631_RESET, 0);
948c2ecf20Sopenharmony_ci}
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistatic bool rt5631_volatile_register(struct device *dev, unsigned int reg)
978c2ecf20Sopenharmony_ci{
988c2ecf20Sopenharmony_ci	switch (reg) {
998c2ecf20Sopenharmony_ci	case RT5631_RESET:
1008c2ecf20Sopenharmony_ci	case RT5631_INT_ST_IRQ_CTRL_2:
1018c2ecf20Sopenharmony_ci	case RT5631_INDEX_ADD:
1028c2ecf20Sopenharmony_ci	case RT5631_INDEX_DATA:
1038c2ecf20Sopenharmony_ci	case RT5631_EQ_CTRL:
1048c2ecf20Sopenharmony_ci		return true;
1058c2ecf20Sopenharmony_ci	default:
1068c2ecf20Sopenharmony_ci		return false;
1078c2ecf20Sopenharmony_ci	}
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic bool rt5631_readable_register(struct device *dev, unsigned int reg)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	switch (reg) {
1138c2ecf20Sopenharmony_ci	case RT5631_RESET:
1148c2ecf20Sopenharmony_ci	case RT5631_SPK_OUT_VOL:
1158c2ecf20Sopenharmony_ci	case RT5631_HP_OUT_VOL:
1168c2ecf20Sopenharmony_ci	case RT5631_MONO_AXO_1_2_VOL:
1178c2ecf20Sopenharmony_ci	case RT5631_AUX_IN_VOL:
1188c2ecf20Sopenharmony_ci	case RT5631_STEREO_DAC_VOL_1:
1198c2ecf20Sopenharmony_ci	case RT5631_MIC_CTRL_1:
1208c2ecf20Sopenharmony_ci	case RT5631_STEREO_DAC_VOL_2:
1218c2ecf20Sopenharmony_ci	case RT5631_ADC_CTRL_1:
1228c2ecf20Sopenharmony_ci	case RT5631_ADC_REC_MIXER:
1238c2ecf20Sopenharmony_ci	case RT5631_ADC_CTRL_2:
1248c2ecf20Sopenharmony_ci	case RT5631_VDAC_DIG_VOL:
1258c2ecf20Sopenharmony_ci	case RT5631_OUTMIXER_L_CTRL:
1268c2ecf20Sopenharmony_ci	case RT5631_OUTMIXER_R_CTRL:
1278c2ecf20Sopenharmony_ci	case RT5631_AXO1MIXER_CTRL:
1288c2ecf20Sopenharmony_ci	case RT5631_AXO2MIXER_CTRL:
1298c2ecf20Sopenharmony_ci	case RT5631_MIC_CTRL_2:
1308c2ecf20Sopenharmony_ci	case RT5631_DIG_MIC_CTRL:
1318c2ecf20Sopenharmony_ci	case RT5631_MONO_INPUT_VOL:
1328c2ecf20Sopenharmony_ci	case RT5631_SPK_MIXER_CTRL:
1338c2ecf20Sopenharmony_ci	case RT5631_SPK_MONO_OUT_CTRL:
1348c2ecf20Sopenharmony_ci	case RT5631_SPK_MONO_HP_OUT_CTRL:
1358c2ecf20Sopenharmony_ci	case RT5631_SDP_CTRL:
1368c2ecf20Sopenharmony_ci	case RT5631_MONO_SDP_CTRL:
1378c2ecf20Sopenharmony_ci	case RT5631_STEREO_AD_DA_CLK_CTRL:
1388c2ecf20Sopenharmony_ci	case RT5631_PWR_MANAG_ADD1:
1398c2ecf20Sopenharmony_ci	case RT5631_PWR_MANAG_ADD2:
1408c2ecf20Sopenharmony_ci	case RT5631_PWR_MANAG_ADD3:
1418c2ecf20Sopenharmony_ci	case RT5631_PWR_MANAG_ADD4:
1428c2ecf20Sopenharmony_ci	case RT5631_GEN_PUR_CTRL_REG:
1438c2ecf20Sopenharmony_ci	case RT5631_GLOBAL_CLK_CTRL:
1448c2ecf20Sopenharmony_ci	case RT5631_PLL_CTRL:
1458c2ecf20Sopenharmony_ci	case RT5631_INT_ST_IRQ_CTRL_1:
1468c2ecf20Sopenharmony_ci	case RT5631_INT_ST_IRQ_CTRL_2:
1478c2ecf20Sopenharmony_ci	case RT5631_GPIO_CTRL:
1488c2ecf20Sopenharmony_ci	case RT5631_MISC_CTRL:
1498c2ecf20Sopenharmony_ci	case RT5631_DEPOP_FUN_CTRL_1:
1508c2ecf20Sopenharmony_ci	case RT5631_DEPOP_FUN_CTRL_2:
1518c2ecf20Sopenharmony_ci	case RT5631_JACK_DET_CTRL:
1528c2ecf20Sopenharmony_ci	case RT5631_SOFT_VOL_CTRL:
1538c2ecf20Sopenharmony_ci	case RT5631_ALC_CTRL_1:
1548c2ecf20Sopenharmony_ci	case RT5631_ALC_CTRL_2:
1558c2ecf20Sopenharmony_ci	case RT5631_ALC_CTRL_3:
1568c2ecf20Sopenharmony_ci	case RT5631_PSEUDO_SPATL_CTRL:
1578c2ecf20Sopenharmony_ci	case RT5631_INDEX_ADD:
1588c2ecf20Sopenharmony_ci	case RT5631_INDEX_DATA:
1598c2ecf20Sopenharmony_ci	case RT5631_EQ_CTRL:
1608c2ecf20Sopenharmony_ci	case RT5631_VENDOR_ID:
1618c2ecf20Sopenharmony_ci	case RT5631_VENDOR_ID1:
1628c2ecf20Sopenharmony_ci	case RT5631_VENDOR_ID2:
1638c2ecf20Sopenharmony_ci		return true;
1648c2ecf20Sopenharmony_ci	default:
1658c2ecf20Sopenharmony_ci		return false;
1668c2ecf20Sopenharmony_ci	}
1678c2ecf20Sopenharmony_ci}
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
1708c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -95625, 375, 0);
1718c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
1728c2ecf20Sopenharmony_ci/* {0, +20, +24, +30, +35, +40, +44, +50, +52}dB */
1738c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_RANGE(mic_bst_tlv,
1748c2ecf20Sopenharmony_ci	0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
1758c2ecf20Sopenharmony_ci	1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
1768c2ecf20Sopenharmony_ci	2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
1778c2ecf20Sopenharmony_ci	3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
1788c2ecf20Sopenharmony_ci	6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
1798c2ecf20Sopenharmony_ci	7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
1808c2ecf20Sopenharmony_ci	8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0)
1818c2ecf20Sopenharmony_ci);
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_cistatic int rt5631_dmic_get(struct snd_kcontrol *kcontrol,
1848c2ecf20Sopenharmony_ci		struct snd_ctl_elem_value *ucontrol)
1858c2ecf20Sopenharmony_ci{
1868c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1878c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	ucontrol->value.integer.value[0] = rt5631->dmic_used_flag;
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	return 0;
1928c2ecf20Sopenharmony_ci}
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_cistatic int rt5631_dmic_put(struct snd_kcontrol *kcontrol,
1958c2ecf20Sopenharmony_ci		struct snd_ctl_elem_value *ucontrol)
1968c2ecf20Sopenharmony_ci{
1978c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1988c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	rt5631->dmic_used_flag = ucontrol->value.integer.value[0];
2018c2ecf20Sopenharmony_ci	return 0;
2028c2ecf20Sopenharmony_ci}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/* MIC Input Type */
2058c2ecf20Sopenharmony_cistatic const char *rt5631_input_mode[] = {
2068c2ecf20Sopenharmony_ci	"Single ended", "Differential"};
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_mic1_mode_enum, RT5631_MIC_CTRL_1,
2098c2ecf20Sopenharmony_ci			    RT5631_MIC1_DIFF_INPUT_SHIFT, rt5631_input_mode);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_mic2_mode_enum, RT5631_MIC_CTRL_1,
2128c2ecf20Sopenharmony_ci			    RT5631_MIC2_DIFF_INPUT_SHIFT, rt5631_input_mode);
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci/* MONO Input Type */
2158c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_monoin_mode_enum, RT5631_MONO_INPUT_VOL,
2168c2ecf20Sopenharmony_ci			    RT5631_MONO_DIFF_INPUT_SHIFT, rt5631_input_mode);
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci/* SPK Ratio Gain Control */
2198c2ecf20Sopenharmony_cistatic const char *rt5631_spk_ratio[] = {"1.00x", "1.09x", "1.27x", "1.44x",
2208c2ecf20Sopenharmony_ci			"1.56x", "1.68x", "1.99x", "2.34x"};
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_spk_ratio_enum, RT5631_GEN_PUR_CTRL_REG,
2238c2ecf20Sopenharmony_ci			    RT5631_SPK_AMP_RATIO_CTRL_SHIFT, rt5631_spk_ratio);
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_snd_controls[] = {
2268c2ecf20Sopenharmony_ci	/* MIC */
2278c2ecf20Sopenharmony_ci	SOC_ENUM("MIC1 Mode Control",  rt5631_mic1_mode_enum),
2288c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("MIC1 Boost Volume", RT5631_MIC_CTRL_2,
2298c2ecf20Sopenharmony_ci		RT5631_MIC1_BOOST_SHIFT, 8, 0, mic_bst_tlv),
2308c2ecf20Sopenharmony_ci	SOC_ENUM("MIC2 Mode Control", rt5631_mic2_mode_enum),
2318c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("MIC2 Boost Volume", RT5631_MIC_CTRL_2,
2328c2ecf20Sopenharmony_ci		RT5631_MIC2_BOOST_SHIFT, 8, 0, mic_bst_tlv),
2338c2ecf20Sopenharmony_ci	/* MONO IN */
2348c2ecf20Sopenharmony_ci	SOC_ENUM("MONOIN Mode Control", rt5631_monoin_mode_enum),
2358c2ecf20Sopenharmony_ci	SOC_DOUBLE_TLV("MONOIN_RX Capture Volume", RT5631_MONO_INPUT_VOL,
2368c2ecf20Sopenharmony_ci			RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
2378c2ecf20Sopenharmony_ci			RT5631_VOL_MASK, 1, in_vol_tlv),
2388c2ecf20Sopenharmony_ci	/* AXI */
2398c2ecf20Sopenharmony_ci	SOC_DOUBLE_TLV("AXI Capture Volume", RT5631_AUX_IN_VOL,
2408c2ecf20Sopenharmony_ci			RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
2418c2ecf20Sopenharmony_ci			RT5631_VOL_MASK, 1, in_vol_tlv),
2428c2ecf20Sopenharmony_ci	/* DAC */
2438c2ecf20Sopenharmony_ci	SOC_DOUBLE_TLV("PCM Playback Volume", RT5631_STEREO_DAC_VOL_2,
2448c2ecf20Sopenharmony_ci			RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
2458c2ecf20Sopenharmony_ci			RT5631_DAC_VOL_MASK, 1, dac_vol_tlv),
2468c2ecf20Sopenharmony_ci	SOC_DOUBLE("PCM Playback Switch", RT5631_STEREO_DAC_VOL_1,
2478c2ecf20Sopenharmony_ci			RT5631_L_MUTE_SHIFT, RT5631_R_MUTE_SHIFT, 1, 1),
2488c2ecf20Sopenharmony_ci	/* AXO */
2498c2ecf20Sopenharmony_ci	SOC_SINGLE("AXO1 Playback Switch", RT5631_MONO_AXO_1_2_VOL,
2508c2ecf20Sopenharmony_ci				RT5631_L_MUTE_SHIFT, 1, 1),
2518c2ecf20Sopenharmony_ci	SOC_SINGLE("AXO2 Playback Switch", RT5631_MONO_AXO_1_2_VOL,
2528c2ecf20Sopenharmony_ci				RT5631_R_VOL_SHIFT, 1, 1),
2538c2ecf20Sopenharmony_ci	/* OUTVOL */
2548c2ecf20Sopenharmony_ci	SOC_DOUBLE("OUTVOL Channel Switch", RT5631_SPK_OUT_VOL,
2558c2ecf20Sopenharmony_ci		RT5631_L_EN_SHIFT, RT5631_R_EN_SHIFT, 1, 0),
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	/* SPK */
2588c2ecf20Sopenharmony_ci	SOC_DOUBLE("Speaker Playback Switch", RT5631_SPK_OUT_VOL,
2598c2ecf20Sopenharmony_ci		RT5631_L_MUTE_SHIFT, RT5631_R_MUTE_SHIFT, 1, 1),
2608c2ecf20Sopenharmony_ci	SOC_DOUBLE_TLV("Speaker Playback Volume", RT5631_SPK_OUT_VOL,
2618c2ecf20Sopenharmony_ci		RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT, 39, 1, out_vol_tlv),
2628c2ecf20Sopenharmony_ci	/* MONO OUT */
2638c2ecf20Sopenharmony_ci	SOC_SINGLE("MONO Playback Switch", RT5631_MONO_AXO_1_2_VOL,
2648c2ecf20Sopenharmony_ci				RT5631_MUTE_MONO_SHIFT, 1, 1),
2658c2ecf20Sopenharmony_ci	/* HP */
2668c2ecf20Sopenharmony_ci	SOC_DOUBLE("HP Playback Switch", RT5631_HP_OUT_VOL,
2678c2ecf20Sopenharmony_ci		RT5631_L_MUTE_SHIFT, RT5631_R_MUTE_SHIFT, 1, 1),
2688c2ecf20Sopenharmony_ci	SOC_DOUBLE_TLV("HP Playback Volume", RT5631_HP_OUT_VOL,
2698c2ecf20Sopenharmony_ci		RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
2708c2ecf20Sopenharmony_ci		RT5631_VOL_MASK, 1, out_vol_tlv),
2718c2ecf20Sopenharmony_ci	/* DMIC */
2728c2ecf20Sopenharmony_ci	SOC_SINGLE_EXT("DMIC Switch", 0, 0, 1, 0,
2738c2ecf20Sopenharmony_ci		rt5631_dmic_get, rt5631_dmic_put),
2748c2ecf20Sopenharmony_ci	SOC_DOUBLE("DMIC Capture Switch", RT5631_DIG_MIC_CTRL,
2758c2ecf20Sopenharmony_ci		RT5631_DMIC_L_CH_MUTE_SHIFT,
2768c2ecf20Sopenharmony_ci		RT5631_DMIC_R_CH_MUTE_SHIFT, 1, 1),
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	/* SPK Ratio Gain Control */
2798c2ecf20Sopenharmony_ci	SOC_ENUM("SPK Ratio Control", rt5631_spk_ratio_enum),
2808c2ecf20Sopenharmony_ci};
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_cistatic int check_sysclk1_source(struct snd_soc_dapm_widget *source,
2838c2ecf20Sopenharmony_ci			 struct snd_soc_dapm_widget *sink)
2848c2ecf20Sopenharmony_ci{
2858c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
2868c2ecf20Sopenharmony_ci	unsigned int reg;
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	reg = snd_soc_component_read(component, RT5631_GLOBAL_CLK_CTRL);
2898c2ecf20Sopenharmony_ci	return reg & RT5631_SYSCLK_SOUR_SEL_PLL;
2908c2ecf20Sopenharmony_ci}
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_cistatic int check_dmic_used(struct snd_soc_dapm_widget *source,
2938c2ecf20Sopenharmony_ci			 struct snd_soc_dapm_widget *sink)
2948c2ecf20Sopenharmony_ci{
2958c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
2968c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
2978c2ecf20Sopenharmony_ci	return rt5631->dmic_used_flag;
2988c2ecf20Sopenharmony_ci}
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_cistatic int check_dacl_to_outmixl(struct snd_soc_dapm_widget *source,
3018c2ecf20Sopenharmony_ci			 struct snd_soc_dapm_widget *sink)
3028c2ecf20Sopenharmony_ci{
3038c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
3048c2ecf20Sopenharmony_ci	unsigned int reg;
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	reg = snd_soc_component_read(component, RT5631_OUTMIXER_L_CTRL);
3078c2ecf20Sopenharmony_ci	return !(reg & RT5631_M_DAC_L_TO_OUTMIXER_L);
3088c2ecf20Sopenharmony_ci}
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_cistatic int check_dacr_to_outmixr(struct snd_soc_dapm_widget *source,
3118c2ecf20Sopenharmony_ci			 struct snd_soc_dapm_widget *sink)
3128c2ecf20Sopenharmony_ci{
3138c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
3148c2ecf20Sopenharmony_ci	unsigned int reg;
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	reg = snd_soc_component_read(component, RT5631_OUTMIXER_R_CTRL);
3178c2ecf20Sopenharmony_ci	return !(reg & RT5631_M_DAC_R_TO_OUTMIXER_R);
3188c2ecf20Sopenharmony_ci}
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_cistatic int check_dacl_to_spkmixl(struct snd_soc_dapm_widget *source,
3218c2ecf20Sopenharmony_ci			 struct snd_soc_dapm_widget *sink)
3228c2ecf20Sopenharmony_ci{
3238c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
3248c2ecf20Sopenharmony_ci	unsigned int reg;
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci	reg = snd_soc_component_read(component, RT5631_SPK_MIXER_CTRL);
3278c2ecf20Sopenharmony_ci	return !(reg & RT5631_M_DAC_L_TO_SPKMIXER_L);
3288c2ecf20Sopenharmony_ci}
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_cistatic int check_dacr_to_spkmixr(struct snd_soc_dapm_widget *source,
3318c2ecf20Sopenharmony_ci			 struct snd_soc_dapm_widget *sink)
3328c2ecf20Sopenharmony_ci{
3338c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
3348c2ecf20Sopenharmony_ci	unsigned int reg;
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	reg = snd_soc_component_read(component, RT5631_SPK_MIXER_CTRL);
3378c2ecf20Sopenharmony_ci	return !(reg & RT5631_M_DAC_R_TO_SPKMIXER_R);
3388c2ecf20Sopenharmony_ci}
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_cistatic int check_adcl_select(struct snd_soc_dapm_widget *source,
3418c2ecf20Sopenharmony_ci			 struct snd_soc_dapm_widget *sink)
3428c2ecf20Sopenharmony_ci{
3438c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
3448c2ecf20Sopenharmony_ci	unsigned int reg;
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci	reg = snd_soc_component_read(component, RT5631_ADC_REC_MIXER);
3478c2ecf20Sopenharmony_ci	return !(reg & RT5631_M_MIC1_TO_RECMIXER_L);
3488c2ecf20Sopenharmony_ci}
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_cistatic int check_adcr_select(struct snd_soc_dapm_widget *source,
3518c2ecf20Sopenharmony_ci			 struct snd_soc_dapm_widget *sink)
3528c2ecf20Sopenharmony_ci{
3538c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
3548c2ecf20Sopenharmony_ci	unsigned int reg;
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	reg = snd_soc_component_read(component, RT5631_ADC_REC_MIXER);
3578c2ecf20Sopenharmony_ci	return !(reg & RT5631_M_MIC2_TO_RECMIXER_R);
3588c2ecf20Sopenharmony_ci}
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci/**
3618c2ecf20Sopenharmony_ci * onebit_depop_power_stage - auto depop in power stage.
3628c2ecf20Sopenharmony_ci * @component: ASoC component
3638c2ecf20Sopenharmony_ci * @enable: power on/off
3648c2ecf20Sopenharmony_ci *
3658c2ecf20Sopenharmony_ci * When power on/off headphone, the depop sequence is done by hardware.
3668c2ecf20Sopenharmony_ci */
3678c2ecf20Sopenharmony_cistatic void onebit_depop_power_stage(struct snd_soc_component *component, int enable)
3688c2ecf20Sopenharmony_ci{
3698c2ecf20Sopenharmony_ci	unsigned int soft_vol, hp_zc;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	/* enable one-bit depop function */
3728c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, RT5631_DEPOP_FUN_CTRL_2,
3738c2ecf20Sopenharmony_ci				RT5631_EN_ONE_BIT_DEPOP, 0);
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	/* keep soft volume and zero crossing setting */
3768c2ecf20Sopenharmony_ci	soft_vol = snd_soc_component_read(component, RT5631_SOFT_VOL_CTRL);
3778c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, 0);
3788c2ecf20Sopenharmony_ci	hp_zc = snd_soc_component_read(component, RT5631_INT_ST_IRQ_CTRL_2);
3798c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
3808c2ecf20Sopenharmony_ci	if (enable) {
3818c2ecf20Sopenharmony_ci		/* config one-bit depop parameter */
3828c2ecf20Sopenharmony_ci		rt5631_write_index(component, RT5631_TEST_MODE_CTRL, 0x84c0);
3838c2ecf20Sopenharmony_ci		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x309f);
3848c2ecf20Sopenharmony_ci		rt5631_write_index(component, RT5631_CP_INTL_REG2, 0x6530);
3858c2ecf20Sopenharmony_ci		/* power on capless block */
3868c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_2,
3878c2ecf20Sopenharmony_ci				RT5631_EN_CAP_FREE_DEPOP);
3888c2ecf20Sopenharmony_ci	} else {
3898c2ecf20Sopenharmony_ci		/* power off capless block */
3908c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_2, 0);
3918c2ecf20Sopenharmony_ci		msleep(100);
3928c2ecf20Sopenharmony_ci	}
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci	/* recover soft volume and zero crossing setting */
3958c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, soft_vol);
3968c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
3978c2ecf20Sopenharmony_ci}
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci/**
4008c2ecf20Sopenharmony_ci * onebit_depop_mute_stage - auto depop in mute stage.
4018c2ecf20Sopenharmony_ci * @component: ASoC component
4028c2ecf20Sopenharmony_ci * @enable: mute/unmute
4038c2ecf20Sopenharmony_ci *
4048c2ecf20Sopenharmony_ci * When mute/unmute headphone, the depop sequence is done by hardware.
4058c2ecf20Sopenharmony_ci */
4068c2ecf20Sopenharmony_cistatic void onebit_depop_mute_stage(struct snd_soc_component *component, int enable)
4078c2ecf20Sopenharmony_ci{
4088c2ecf20Sopenharmony_ci	unsigned int soft_vol, hp_zc;
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	/* enable one-bit depop function */
4118c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, RT5631_DEPOP_FUN_CTRL_2,
4128c2ecf20Sopenharmony_ci				RT5631_EN_ONE_BIT_DEPOP, 0);
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	/* keep soft volume and zero crossing setting */
4158c2ecf20Sopenharmony_ci	soft_vol = snd_soc_component_read(component, RT5631_SOFT_VOL_CTRL);
4168c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, 0);
4178c2ecf20Sopenharmony_ci	hp_zc = snd_soc_component_read(component, RT5631_INT_ST_IRQ_CTRL_2);
4188c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
4198c2ecf20Sopenharmony_ci	if (enable) {
4208c2ecf20Sopenharmony_ci		schedule_timeout_uninterruptible(msecs_to_jiffies(10));
4218c2ecf20Sopenharmony_ci		/* config one-bit depop parameter */
4228c2ecf20Sopenharmony_ci		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x307f);
4238c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_HP_OUT_VOL,
4248c2ecf20Sopenharmony_ci				RT5631_L_MUTE | RT5631_R_MUTE, 0);
4258c2ecf20Sopenharmony_ci		msleep(300);
4268c2ecf20Sopenharmony_ci	} else {
4278c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_HP_OUT_VOL,
4288c2ecf20Sopenharmony_ci			RT5631_L_MUTE | RT5631_R_MUTE,
4298c2ecf20Sopenharmony_ci			RT5631_L_MUTE | RT5631_R_MUTE);
4308c2ecf20Sopenharmony_ci		msleep(100);
4318c2ecf20Sopenharmony_ci	}
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci	/* recover soft volume and zero crossing setting */
4348c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, soft_vol);
4358c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
4368c2ecf20Sopenharmony_ci}
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci/**
4398c2ecf20Sopenharmony_ci * onebit_depop_power_stage - step by step depop sequence in power stage.
4408c2ecf20Sopenharmony_ci * @component: ASoC component
4418c2ecf20Sopenharmony_ci * @enable: power on/off
4428c2ecf20Sopenharmony_ci *
4438c2ecf20Sopenharmony_ci * When power on/off headphone, the depop sequence is done in step by step.
4448c2ecf20Sopenharmony_ci */
4458c2ecf20Sopenharmony_cistatic void depop_seq_power_stage(struct snd_soc_component *component, int enable)
4468c2ecf20Sopenharmony_ci{
4478c2ecf20Sopenharmony_ci	unsigned int soft_vol, hp_zc;
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	/* depop control by register */
4508c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, RT5631_DEPOP_FUN_CTRL_2,
4518c2ecf20Sopenharmony_ci		RT5631_EN_ONE_BIT_DEPOP, RT5631_EN_ONE_BIT_DEPOP);
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	/* keep soft volume and zero crossing setting */
4548c2ecf20Sopenharmony_ci	soft_vol = snd_soc_component_read(component, RT5631_SOFT_VOL_CTRL);
4558c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, 0);
4568c2ecf20Sopenharmony_ci	hp_zc = snd_soc_component_read(component, RT5631_INT_ST_IRQ_CTRL_2);
4578c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
4588c2ecf20Sopenharmony_ci	if (enable) {
4598c2ecf20Sopenharmony_ci		/* config depop sequence parameter */
4608c2ecf20Sopenharmony_ci		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x303e);
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci		/* power on headphone and charge pump */
4638c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
4648c2ecf20Sopenharmony_ci			RT5631_PWR_CHARGE_PUMP | RT5631_PWR_HP_L_AMP |
4658c2ecf20Sopenharmony_ci			RT5631_PWR_HP_R_AMP,
4668c2ecf20Sopenharmony_ci			RT5631_PWR_CHARGE_PUMP | RT5631_PWR_HP_L_AMP |
4678c2ecf20Sopenharmony_ci			RT5631_PWR_HP_R_AMP);
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci		/* power on soft generator and depop mode2 */
4708c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
4718c2ecf20Sopenharmony_ci			RT5631_POW_ON_SOFT_GEN | RT5631_EN_DEPOP2_FOR_HP);
4728c2ecf20Sopenharmony_ci		msleep(100);
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci		/* stop depop mode */
4758c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
4768c2ecf20Sopenharmony_ci			RT5631_PWR_HP_DEPOP_DIS, RT5631_PWR_HP_DEPOP_DIS);
4778c2ecf20Sopenharmony_ci	} else {
4788c2ecf20Sopenharmony_ci		/* config depop sequence parameter */
4798c2ecf20Sopenharmony_ci		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x303F);
4808c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
4818c2ecf20Sopenharmony_ci			RT5631_POW_ON_SOFT_GEN | RT5631_EN_MUTE_UNMUTE_DEPOP |
4828c2ecf20Sopenharmony_ci			RT5631_PD_HPAMP_L_ST_UP | RT5631_PD_HPAMP_R_ST_UP);
4838c2ecf20Sopenharmony_ci		msleep(75);
4848c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
4858c2ecf20Sopenharmony_ci			RT5631_POW_ON_SOFT_GEN | RT5631_PD_HPAMP_L_ST_UP |
4868c2ecf20Sopenharmony_ci			RT5631_PD_HPAMP_R_ST_UP);
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ci		/* start depop mode */
4898c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
4908c2ecf20Sopenharmony_ci				RT5631_PWR_HP_DEPOP_DIS, 0);
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci		/* config depop sequence parameter */
4938c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
4948c2ecf20Sopenharmony_ci			RT5631_POW_ON_SOFT_GEN | RT5631_EN_DEPOP2_FOR_HP |
4958c2ecf20Sopenharmony_ci			RT5631_PD_HPAMP_L_ST_UP | RT5631_PD_HPAMP_R_ST_UP);
4968c2ecf20Sopenharmony_ci		msleep(80);
4978c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
4988c2ecf20Sopenharmony_ci			RT5631_POW_ON_SOFT_GEN);
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci		/* power down headphone and charge pump */
5018c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
5028c2ecf20Sopenharmony_ci			RT5631_PWR_CHARGE_PUMP | RT5631_PWR_HP_L_AMP |
5038c2ecf20Sopenharmony_ci			RT5631_PWR_HP_R_AMP, 0);
5048c2ecf20Sopenharmony_ci	}
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ci	/* recover soft volume and zero crossing setting */
5078c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, soft_vol);
5088c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
5098c2ecf20Sopenharmony_ci}
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci/**
5128c2ecf20Sopenharmony_ci * depop_seq_mute_stage - step by step depop sequence in mute stage.
5138c2ecf20Sopenharmony_ci * @component: ASoC component
5148c2ecf20Sopenharmony_ci * @enable: mute/unmute
5158c2ecf20Sopenharmony_ci *
5168c2ecf20Sopenharmony_ci * When mute/unmute headphone, the depop sequence is done in step by step.
5178c2ecf20Sopenharmony_ci */
5188c2ecf20Sopenharmony_cistatic void depop_seq_mute_stage(struct snd_soc_component *component, int enable)
5198c2ecf20Sopenharmony_ci{
5208c2ecf20Sopenharmony_ci	unsigned int soft_vol, hp_zc;
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci	/* depop control by register */
5238c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, RT5631_DEPOP_FUN_CTRL_2,
5248c2ecf20Sopenharmony_ci		RT5631_EN_ONE_BIT_DEPOP, RT5631_EN_ONE_BIT_DEPOP);
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ci	/* keep soft volume and zero crossing setting */
5278c2ecf20Sopenharmony_ci	soft_vol = snd_soc_component_read(component, RT5631_SOFT_VOL_CTRL);
5288c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, 0);
5298c2ecf20Sopenharmony_ci	hp_zc = snd_soc_component_read(component, RT5631_INT_ST_IRQ_CTRL_2);
5308c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
5318c2ecf20Sopenharmony_ci	if (enable) {
5328c2ecf20Sopenharmony_ci		schedule_timeout_uninterruptible(msecs_to_jiffies(10));
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_ci		/* config depop sequence parameter */
5358c2ecf20Sopenharmony_ci		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x302f);
5368c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
5378c2ecf20Sopenharmony_ci			RT5631_POW_ON_SOFT_GEN | RT5631_EN_MUTE_UNMUTE_DEPOP |
5388c2ecf20Sopenharmony_ci			RT5631_EN_HP_R_M_UN_MUTE_DEPOP |
5398c2ecf20Sopenharmony_ci			RT5631_EN_HP_L_M_UN_MUTE_DEPOP);
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_HP_OUT_VOL,
5428c2ecf20Sopenharmony_ci				RT5631_L_MUTE | RT5631_R_MUTE, 0);
5438c2ecf20Sopenharmony_ci		msleep(160);
5448c2ecf20Sopenharmony_ci	} else {
5458c2ecf20Sopenharmony_ci		/* config depop sequence parameter */
5468c2ecf20Sopenharmony_ci		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x302f);
5478c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
5488c2ecf20Sopenharmony_ci			RT5631_POW_ON_SOFT_GEN | RT5631_EN_MUTE_UNMUTE_DEPOP |
5498c2ecf20Sopenharmony_ci			RT5631_EN_HP_R_M_UN_MUTE_DEPOP |
5508c2ecf20Sopenharmony_ci			RT5631_EN_HP_L_M_UN_MUTE_DEPOP);
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_HP_OUT_VOL,
5538c2ecf20Sopenharmony_ci			RT5631_L_MUTE | RT5631_R_MUTE,
5548c2ecf20Sopenharmony_ci			RT5631_L_MUTE | RT5631_R_MUTE);
5558c2ecf20Sopenharmony_ci		msleep(150);
5568c2ecf20Sopenharmony_ci	}
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci	/* recover soft volume and zero crossing setting */
5598c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, soft_vol);
5608c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
5618c2ecf20Sopenharmony_ci}
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_cistatic int hp_event(struct snd_soc_dapm_widget *w,
5648c2ecf20Sopenharmony_ci	struct snd_kcontrol *kcontrol, int event)
5658c2ecf20Sopenharmony_ci{
5668c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
5678c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_ci	switch (event) {
5708c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMD:
5718c2ecf20Sopenharmony_ci		if (rt5631->codec_version) {
5728c2ecf20Sopenharmony_ci			onebit_depop_mute_stage(component, 0);
5738c2ecf20Sopenharmony_ci			onebit_depop_power_stage(component, 0);
5748c2ecf20Sopenharmony_ci		} else {
5758c2ecf20Sopenharmony_ci			depop_seq_mute_stage(component, 0);
5768c2ecf20Sopenharmony_ci			depop_seq_power_stage(component, 0);
5778c2ecf20Sopenharmony_ci		}
5788c2ecf20Sopenharmony_ci		break;
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
5818c2ecf20Sopenharmony_ci		if (rt5631->codec_version) {
5828c2ecf20Sopenharmony_ci			onebit_depop_power_stage(component, 1);
5838c2ecf20Sopenharmony_ci			onebit_depop_mute_stage(component, 1);
5848c2ecf20Sopenharmony_ci		} else {
5858c2ecf20Sopenharmony_ci			depop_seq_power_stage(component, 1);
5868c2ecf20Sopenharmony_ci			depop_seq_mute_stage(component, 1);
5878c2ecf20Sopenharmony_ci		}
5888c2ecf20Sopenharmony_ci		break;
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci	default:
5918c2ecf20Sopenharmony_ci		break;
5928c2ecf20Sopenharmony_ci	}
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ci	return 0;
5958c2ecf20Sopenharmony_ci}
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_cistatic int set_dmic_params(struct snd_soc_dapm_widget *w,
5988c2ecf20Sopenharmony_ci	struct snd_kcontrol *kcontrol, int event)
5998c2ecf20Sopenharmony_ci{
6008c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
6018c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci	switch (rt5631->rx_rate) {
6048c2ecf20Sopenharmony_ci	case 44100:
6058c2ecf20Sopenharmony_ci	case 48000:
6068c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_DIG_MIC_CTRL,
6078c2ecf20Sopenharmony_ci			RT5631_DMIC_CLK_CTRL_MASK,
6088c2ecf20Sopenharmony_ci			RT5631_DMIC_CLK_CTRL_TO_32FS);
6098c2ecf20Sopenharmony_ci		break;
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci	case 32000:
6128c2ecf20Sopenharmony_ci	case 22050:
6138c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_DIG_MIC_CTRL,
6148c2ecf20Sopenharmony_ci			RT5631_DMIC_CLK_CTRL_MASK,
6158c2ecf20Sopenharmony_ci			RT5631_DMIC_CLK_CTRL_TO_64FS);
6168c2ecf20Sopenharmony_ci		break;
6178c2ecf20Sopenharmony_ci
6188c2ecf20Sopenharmony_ci	case 16000:
6198c2ecf20Sopenharmony_ci	case 11025:
6208c2ecf20Sopenharmony_ci	case 8000:
6218c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_DIG_MIC_CTRL,
6228c2ecf20Sopenharmony_ci			RT5631_DMIC_CLK_CTRL_MASK,
6238c2ecf20Sopenharmony_ci			RT5631_DMIC_CLK_CTRL_TO_128FS);
6248c2ecf20Sopenharmony_ci		break;
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci	default:
6278c2ecf20Sopenharmony_ci		return -EINVAL;
6288c2ecf20Sopenharmony_ci	}
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_ci	return 0;
6318c2ecf20Sopenharmony_ci}
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_recmixl_mixer_controls[] = {
6348c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("OUTMIXL Capture Switch", RT5631_ADC_REC_MIXER,
6358c2ecf20Sopenharmony_ci			RT5631_M_OUTMIXL_RECMIXL_BIT, 1, 1),
6368c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC1_BST1 Capture Switch", RT5631_ADC_REC_MIXER,
6378c2ecf20Sopenharmony_ci			RT5631_M_MIC1_RECMIXL_BIT, 1, 1),
6388c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("AXILVOL Capture Switch", RT5631_ADC_REC_MIXER,
6398c2ecf20Sopenharmony_ci			RT5631_M_AXIL_RECMIXL_BIT, 1, 1),
6408c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MONOIN_RX Capture Switch", RT5631_ADC_REC_MIXER,
6418c2ecf20Sopenharmony_ci			RT5631_M_MONO_IN_RECMIXL_BIT, 1, 1),
6428c2ecf20Sopenharmony_ci};
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_recmixr_mixer_controls[] = {
6458c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MONOIN_RX Capture Switch", RT5631_ADC_REC_MIXER,
6468c2ecf20Sopenharmony_ci			RT5631_M_MONO_IN_RECMIXR_BIT, 1, 1),
6478c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("AXIRVOL Capture Switch", RT5631_ADC_REC_MIXER,
6488c2ecf20Sopenharmony_ci			RT5631_M_AXIR_RECMIXR_BIT, 1, 1),
6498c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC2_BST2 Capture Switch", RT5631_ADC_REC_MIXER,
6508c2ecf20Sopenharmony_ci			RT5631_M_MIC2_RECMIXR_BIT, 1, 1),
6518c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("OUTMIXR Capture Switch", RT5631_ADC_REC_MIXER,
6528c2ecf20Sopenharmony_ci			RT5631_M_OUTMIXR_RECMIXR_BIT, 1, 1),
6538c2ecf20Sopenharmony_ci};
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_spkmixl_mixer_controls[] = {
6568c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("RECMIXL Playback Switch", RT5631_SPK_MIXER_CTRL,
6578c2ecf20Sopenharmony_ci			RT5631_M_RECMIXL_SPKMIXL_BIT, 1, 1),
6588c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC1_P Playback Switch", RT5631_SPK_MIXER_CTRL,
6598c2ecf20Sopenharmony_ci			RT5631_M_MIC1P_SPKMIXL_BIT, 1, 1),
6608c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("DACL Playback Switch", RT5631_SPK_MIXER_CTRL,
6618c2ecf20Sopenharmony_ci			RT5631_M_DACL_SPKMIXL_BIT, 1, 1),
6628c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("OUTMIXL Playback Switch", RT5631_SPK_MIXER_CTRL,
6638c2ecf20Sopenharmony_ci			RT5631_M_OUTMIXL_SPKMIXL_BIT, 1, 1),
6648c2ecf20Sopenharmony_ci};
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_spkmixr_mixer_controls[] = {
6678c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("OUTMIXR Playback Switch", RT5631_SPK_MIXER_CTRL,
6688c2ecf20Sopenharmony_ci			RT5631_M_OUTMIXR_SPKMIXR_BIT, 1, 1),
6698c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("DACR Playback Switch", RT5631_SPK_MIXER_CTRL,
6708c2ecf20Sopenharmony_ci			RT5631_M_DACR_SPKMIXR_BIT, 1, 1),
6718c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC2_P Playback Switch", RT5631_SPK_MIXER_CTRL,
6728c2ecf20Sopenharmony_ci			RT5631_M_MIC2P_SPKMIXR_BIT, 1, 1),
6738c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("RECMIXR Playback Switch", RT5631_SPK_MIXER_CTRL,
6748c2ecf20Sopenharmony_ci			RT5631_M_RECMIXR_SPKMIXR_BIT, 1, 1),
6758c2ecf20Sopenharmony_ci};
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_outmixl_mixer_controls[] = {
6788c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("RECMIXL Playback Switch", RT5631_OUTMIXER_L_CTRL,
6798c2ecf20Sopenharmony_ci				RT5631_M_RECMIXL_OUTMIXL_BIT, 1, 1),
6808c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("RECMIXR Playback Switch", RT5631_OUTMIXER_L_CTRL,
6818c2ecf20Sopenharmony_ci				RT5631_M_RECMIXR_OUTMIXL_BIT, 1, 1),
6828c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("DACL Playback Switch", RT5631_OUTMIXER_L_CTRL,
6838c2ecf20Sopenharmony_ci				RT5631_M_DACL_OUTMIXL_BIT, 1, 1),
6848c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_OUTMIXER_L_CTRL,
6858c2ecf20Sopenharmony_ci				RT5631_M_MIC1_OUTMIXL_BIT, 1, 1),
6868c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_OUTMIXER_L_CTRL,
6878c2ecf20Sopenharmony_ci				RT5631_M_MIC2_OUTMIXL_BIT, 1, 1),
6888c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MONOIN_RXP Playback Switch", RT5631_OUTMIXER_L_CTRL,
6898c2ecf20Sopenharmony_ci				RT5631_M_MONO_INP_OUTMIXL_BIT, 1, 1),
6908c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("AXILVOL Playback Switch", RT5631_OUTMIXER_L_CTRL,
6918c2ecf20Sopenharmony_ci				RT5631_M_AXIL_OUTMIXL_BIT, 1, 1),
6928c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("AXIRVOL Playback Switch", RT5631_OUTMIXER_L_CTRL,
6938c2ecf20Sopenharmony_ci				RT5631_M_AXIR_OUTMIXL_BIT, 1, 1),
6948c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("VDAC Playback Switch", RT5631_OUTMIXER_L_CTRL,
6958c2ecf20Sopenharmony_ci				RT5631_M_VDAC_OUTMIXL_BIT, 1, 1),
6968c2ecf20Sopenharmony_ci};
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_outmixr_mixer_controls[] = {
6998c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("VDAC Playback Switch", RT5631_OUTMIXER_R_CTRL,
7008c2ecf20Sopenharmony_ci				RT5631_M_VDAC_OUTMIXR_BIT, 1, 1),
7018c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("AXIRVOL Playback Switch", RT5631_OUTMIXER_R_CTRL,
7028c2ecf20Sopenharmony_ci				RT5631_M_AXIR_OUTMIXR_BIT, 1, 1),
7038c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("AXILVOL Playback Switch", RT5631_OUTMIXER_R_CTRL,
7048c2ecf20Sopenharmony_ci				RT5631_M_AXIL_OUTMIXR_BIT, 1, 1),
7058c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MONOIN_RXN Playback Switch", RT5631_OUTMIXER_R_CTRL,
7068c2ecf20Sopenharmony_ci				RT5631_M_MONO_INN_OUTMIXR_BIT, 1, 1),
7078c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_OUTMIXER_R_CTRL,
7088c2ecf20Sopenharmony_ci				RT5631_M_MIC2_OUTMIXR_BIT, 1, 1),
7098c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_OUTMIXER_R_CTRL,
7108c2ecf20Sopenharmony_ci				RT5631_M_MIC1_OUTMIXR_BIT, 1, 1),
7118c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("DACR Playback Switch", RT5631_OUTMIXER_R_CTRL,
7128c2ecf20Sopenharmony_ci				RT5631_M_DACR_OUTMIXR_BIT, 1, 1),
7138c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("RECMIXR Playback Switch", RT5631_OUTMIXER_R_CTRL,
7148c2ecf20Sopenharmony_ci				RT5631_M_RECMIXR_OUTMIXR_BIT, 1, 1),
7158c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("RECMIXL Playback Switch", RT5631_OUTMIXER_R_CTRL,
7168c2ecf20Sopenharmony_ci				RT5631_M_RECMIXL_OUTMIXR_BIT, 1, 1),
7178c2ecf20Sopenharmony_ci};
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_AXO1MIX_mixer_controls[] = {
7208c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_AXO1MIXER_CTRL,
7218c2ecf20Sopenharmony_ci				RT5631_M_MIC1_AXO1MIX_BIT , 1, 1),
7228c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_AXO1MIXER_CTRL,
7238c2ecf20Sopenharmony_ci				RT5631_M_MIC2_AXO1MIX_BIT, 1, 1),
7248c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("OUTVOLL Playback Switch", RT5631_AXO1MIXER_CTRL,
7258c2ecf20Sopenharmony_ci				RT5631_M_OUTMIXL_AXO1MIX_BIT , 1 , 1),
7268c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("OUTVOLR Playback Switch", RT5631_AXO1MIXER_CTRL,
7278c2ecf20Sopenharmony_ci				RT5631_M_OUTMIXR_AXO1MIX_BIT, 1, 1),
7288c2ecf20Sopenharmony_ci};
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_AXO2MIX_mixer_controls[] = {
7318c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_AXO2MIXER_CTRL,
7328c2ecf20Sopenharmony_ci				RT5631_M_MIC1_AXO2MIX_BIT, 1, 1),
7338c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_AXO2MIXER_CTRL,
7348c2ecf20Sopenharmony_ci				RT5631_M_MIC2_AXO2MIX_BIT, 1, 1),
7358c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("OUTVOLL Playback Switch", RT5631_AXO2MIXER_CTRL,
7368c2ecf20Sopenharmony_ci				RT5631_M_OUTMIXL_AXO2MIX_BIT, 1, 1),
7378c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("OUTVOLR Playback Switch", RT5631_AXO2MIXER_CTRL,
7388c2ecf20Sopenharmony_ci				RT5631_M_OUTMIXR_AXO2MIX_BIT, 1 , 1),
7398c2ecf20Sopenharmony_ci};
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_spolmix_mixer_controls[] = {
7428c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("SPKVOLL Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
7438c2ecf20Sopenharmony_ci				RT5631_M_SPKVOLL_SPOLMIX_BIT, 1, 1),
7448c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("SPKVOLR Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
7458c2ecf20Sopenharmony_ci				RT5631_M_SPKVOLR_SPOLMIX_BIT, 1, 1),
7468c2ecf20Sopenharmony_ci};
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_spormix_mixer_controls[] = {
7498c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("SPKVOLL Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
7508c2ecf20Sopenharmony_ci				RT5631_M_SPKVOLL_SPORMIX_BIT, 1, 1),
7518c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("SPKVOLR Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
7528c2ecf20Sopenharmony_ci				RT5631_M_SPKVOLR_SPORMIX_BIT, 1, 1),
7538c2ecf20Sopenharmony_ci};
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_monomix_mixer_controls[] = {
7568c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("OUTVOLL Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
7578c2ecf20Sopenharmony_ci				RT5631_M_OUTVOLL_MONOMIX_BIT, 1, 1),
7588c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("OUTVOLR Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
7598c2ecf20Sopenharmony_ci				RT5631_M_OUTVOLR_MONOMIX_BIT, 1, 1),
7608c2ecf20Sopenharmony_ci};
7618c2ecf20Sopenharmony_ci
7628c2ecf20Sopenharmony_ci/* Left SPK Volume Input */
7638c2ecf20Sopenharmony_cistatic const char *rt5631_spkvoll_sel[] = {"Vmid", "SPKMIXL"};
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_spkvoll_enum, RT5631_SPK_OUT_VOL,
7668c2ecf20Sopenharmony_ci			    RT5631_L_EN_SHIFT, rt5631_spkvoll_sel);
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_spkvoll_mux_control =
7698c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("Left SPKVOL SRC", rt5631_spkvoll_enum);
7708c2ecf20Sopenharmony_ci
7718c2ecf20Sopenharmony_ci/* Left HP Volume Input */
7728c2ecf20Sopenharmony_cistatic const char *rt5631_hpvoll_sel[] = {"Vmid", "OUTMIXL"};
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_hpvoll_enum, RT5631_HP_OUT_VOL,
7758c2ecf20Sopenharmony_ci			    RT5631_L_EN_SHIFT, rt5631_hpvoll_sel);
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_hpvoll_mux_control =
7788c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("Left HPVOL SRC", rt5631_hpvoll_enum);
7798c2ecf20Sopenharmony_ci
7808c2ecf20Sopenharmony_ci/* Left Out Volume Input */
7818c2ecf20Sopenharmony_cistatic const char *rt5631_outvoll_sel[] = {"Vmid", "OUTMIXL"};
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_outvoll_enum, RT5631_MONO_AXO_1_2_VOL,
7848c2ecf20Sopenharmony_ci			    RT5631_L_EN_SHIFT, rt5631_outvoll_sel);
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_outvoll_mux_control =
7878c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("Left OUTVOL SRC", rt5631_outvoll_enum);
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci/* Right Out Volume Input */
7908c2ecf20Sopenharmony_cistatic const char *rt5631_outvolr_sel[] = {"Vmid", "OUTMIXR"};
7918c2ecf20Sopenharmony_ci
7928c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_outvolr_enum, RT5631_MONO_AXO_1_2_VOL,
7938c2ecf20Sopenharmony_ci			    RT5631_R_EN_SHIFT, rt5631_outvolr_sel);
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_outvolr_mux_control =
7968c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("Right OUTVOL SRC", rt5631_outvolr_enum);
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci/* Right HP Volume Input */
7998c2ecf20Sopenharmony_cistatic const char *rt5631_hpvolr_sel[] = {"Vmid", "OUTMIXR"};
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_hpvolr_enum, RT5631_HP_OUT_VOL,
8028c2ecf20Sopenharmony_ci			    RT5631_R_EN_SHIFT, rt5631_hpvolr_sel);
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_hpvolr_mux_control =
8058c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("Right HPVOL SRC", rt5631_hpvolr_enum);
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_ci/* Right SPK Volume Input */
8088c2ecf20Sopenharmony_cistatic const char *rt5631_spkvolr_sel[] = {"Vmid", "SPKMIXR"};
8098c2ecf20Sopenharmony_ci
8108c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_spkvolr_enum, RT5631_SPK_OUT_VOL,
8118c2ecf20Sopenharmony_ci			    RT5631_R_EN_SHIFT, rt5631_spkvolr_sel);
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_spkvolr_mux_control =
8148c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("Right SPKVOL SRC", rt5631_spkvolr_enum);
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci/* SPO Left Channel Input */
8178c2ecf20Sopenharmony_cistatic const char *rt5631_spol_src_sel[] = {
8188c2ecf20Sopenharmony_ci	"SPOLMIX", "MONOIN_RX", "VDAC", "DACL"};
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_spol_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
8218c2ecf20Sopenharmony_ci			    RT5631_SPK_L_MUX_SEL_SHIFT, rt5631_spol_src_sel);
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_spol_mux_control =
8248c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("SPOL SRC", rt5631_spol_src_enum);
8258c2ecf20Sopenharmony_ci
8268c2ecf20Sopenharmony_ci/* SPO Right Channel Input */
8278c2ecf20Sopenharmony_cistatic const char *rt5631_spor_src_sel[] = {
8288c2ecf20Sopenharmony_ci	"SPORMIX", "MONOIN_RX", "VDAC", "DACR"};
8298c2ecf20Sopenharmony_ci
8308c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_spor_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
8318c2ecf20Sopenharmony_ci			    RT5631_SPK_R_MUX_SEL_SHIFT, rt5631_spor_src_sel);
8328c2ecf20Sopenharmony_ci
8338c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_spor_mux_control =
8348c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("SPOR SRC", rt5631_spor_src_enum);
8358c2ecf20Sopenharmony_ci
8368c2ecf20Sopenharmony_ci/* MONO Input */
8378c2ecf20Sopenharmony_cistatic const char *rt5631_mono_src_sel[] = {"MONOMIX", "MONOIN_RX", "VDAC"};
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_mono_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
8408c2ecf20Sopenharmony_ci			    RT5631_MONO_MUX_SEL_SHIFT, rt5631_mono_src_sel);
8418c2ecf20Sopenharmony_ci
8428c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_mono_mux_control =
8438c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("MONO SRC", rt5631_mono_src_enum);
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ci/* Left HPO Input */
8468c2ecf20Sopenharmony_cistatic const char *rt5631_hpl_src_sel[] = {"Left HPVOL", "Left DAC"};
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_hpl_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
8498c2ecf20Sopenharmony_ci			    RT5631_HP_L_MUX_SEL_SHIFT, rt5631_hpl_src_sel);
8508c2ecf20Sopenharmony_ci
8518c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_hpl_mux_control =
8528c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("HPL SRC", rt5631_hpl_src_enum);
8538c2ecf20Sopenharmony_ci
8548c2ecf20Sopenharmony_ci/* Right HPO Input */
8558c2ecf20Sopenharmony_cistatic const char *rt5631_hpr_src_sel[] = {"Right HPVOL", "Right DAC"};
8568c2ecf20Sopenharmony_ci
8578c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5631_hpr_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
8588c2ecf20Sopenharmony_ci			    RT5631_HP_R_MUX_SEL_SHIFT, rt5631_hpr_src_sel);
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5631_hpr_mux_control =
8618c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("HPR SRC", rt5631_hpr_src_enum);
8628c2ecf20Sopenharmony_ci
8638c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget rt5631_dapm_widgets[] = {
8648c2ecf20Sopenharmony_ci	/* Vmid */
8658c2ecf20Sopenharmony_ci	SND_SOC_DAPM_VMID("Vmid"),
8668c2ecf20Sopenharmony_ci	/* PLL1 */
8678c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("PLL1", RT5631_PWR_MANAG_ADD2,
8688c2ecf20Sopenharmony_ci			RT5631_PWR_PLL1_BIT, 0, NULL, 0),
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_ci	/* Input Side */
8718c2ecf20Sopenharmony_ci	/* Input Lines */
8728c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("MIC1"),
8738c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("MIC2"),
8748c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AXIL"),
8758c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AXIR"),
8768c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("MONOIN_RXN"),
8778c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("MONOIN_RXP"),
8788c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("DMIC"),
8798c2ecf20Sopenharmony_ci
8808c2ecf20Sopenharmony_ci	/* MICBIAS */
8818c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MICBIAS("MIC Bias1", RT5631_PWR_MANAG_ADD2,
8828c2ecf20Sopenharmony_ci			RT5631_PWR_MICBIAS1_VOL_BIT, 0),
8838c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MICBIAS("MIC Bias2", RT5631_PWR_MANAG_ADD2,
8848c2ecf20Sopenharmony_ci			RT5631_PWR_MICBIAS2_VOL_BIT, 0),
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_ci	/* Boost */
8878c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("MIC1 Boost", RT5631_PWR_MANAG_ADD2,
8888c2ecf20Sopenharmony_ci			RT5631_PWR_MIC1_BOOT_GAIN_BIT, 0, NULL, 0),
8898c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("MIC2 Boost", RT5631_PWR_MANAG_ADD2,
8908c2ecf20Sopenharmony_ci			RT5631_PWR_MIC2_BOOT_GAIN_BIT, 0, NULL, 0),
8918c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("MONOIN_RXP Boost", RT5631_PWR_MANAG_ADD4,
8928c2ecf20Sopenharmony_ci			RT5631_PWR_MONO_IN_P_VOL_BIT, 0, NULL, 0),
8938c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("MONOIN_RXN Boost", RT5631_PWR_MANAG_ADD4,
8948c2ecf20Sopenharmony_ci			RT5631_PWR_MONO_IN_N_VOL_BIT, 0, NULL, 0),
8958c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("AXIL Boost", RT5631_PWR_MANAG_ADD4,
8968c2ecf20Sopenharmony_ci			RT5631_PWR_AXIL_IN_VOL_BIT, 0, NULL, 0),
8978c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("AXIR Boost", RT5631_PWR_MANAG_ADD4,
8988c2ecf20Sopenharmony_ci			RT5631_PWR_AXIR_IN_VOL_BIT, 0, NULL, 0),
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_ci	/* MONO In */
9018c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("MONO_IN", SND_SOC_NOPM, 0, 0, NULL, 0),
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci	/* REC Mixer */
9048c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("RECMIXL Mixer", RT5631_PWR_MANAG_ADD2,
9058c2ecf20Sopenharmony_ci		RT5631_PWR_RECMIXER_L_BIT, 0,
9068c2ecf20Sopenharmony_ci		&rt5631_recmixl_mixer_controls[0],
9078c2ecf20Sopenharmony_ci		ARRAY_SIZE(rt5631_recmixl_mixer_controls)),
9088c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("RECMIXR Mixer", RT5631_PWR_MANAG_ADD2,
9098c2ecf20Sopenharmony_ci		RT5631_PWR_RECMIXER_R_BIT, 0,
9108c2ecf20Sopenharmony_ci		&rt5631_recmixr_mixer_controls[0],
9118c2ecf20Sopenharmony_ci		ARRAY_SIZE(rt5631_recmixr_mixer_controls)),
9128c2ecf20Sopenharmony_ci	/* Because of record duplication for L/R channel,
9138c2ecf20Sopenharmony_ci	 * L/R ADCs need power up at the same time */
9148c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("ADC Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_ci	/* DMIC */
9178c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("DMIC Supply", RT5631_DIG_MIC_CTRL,
9188c2ecf20Sopenharmony_ci		RT5631_DMIC_ENA_SHIFT, 0,
9198c2ecf20Sopenharmony_ci		set_dmic_params, SND_SOC_DAPM_PRE_PMU),
9208c2ecf20Sopenharmony_ci	/* ADC Data Srouce */
9218c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("Left ADC Select", RT5631_INT_ST_IRQ_CTRL_2,
9228c2ecf20Sopenharmony_ci			RT5631_ADC_DATA_SEL_MIC1_SHIFT, 0, NULL, 0),
9238c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("Right ADC Select", RT5631_INT_ST_IRQ_CTRL_2,
9248c2ecf20Sopenharmony_ci			RT5631_ADC_DATA_SEL_MIC2_SHIFT, 0, NULL, 0),
9258c2ecf20Sopenharmony_ci
9268c2ecf20Sopenharmony_ci	/* ADCs */
9278c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("Left ADC", "HIFI Capture",
9288c2ecf20Sopenharmony_ci		RT5631_PWR_MANAG_ADD1, RT5631_PWR_ADC_L_CLK_BIT, 0),
9298c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("Right ADC", "HIFI Capture",
9308c2ecf20Sopenharmony_ci		RT5631_PWR_MANAG_ADD1, RT5631_PWR_ADC_R_CLK_BIT, 0),
9318c2ecf20Sopenharmony_ci
9328c2ecf20Sopenharmony_ci	/* DAC and ADC supply power */
9338c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("I2S", RT5631_PWR_MANAG_ADD1,
9348c2ecf20Sopenharmony_ci			RT5631_PWR_MAIN_I2S_BIT, 0, NULL, 0),
9358c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("DAC REF", RT5631_PWR_MANAG_ADD1,
9368c2ecf20Sopenharmony_ci			RT5631_PWR_DAC_REF_BIT, 0, NULL, 0),
9378c2ecf20Sopenharmony_ci
9388c2ecf20Sopenharmony_ci	/* Output Side */
9398c2ecf20Sopenharmony_ci	/* DACs */
9408c2ecf20Sopenharmony_ci	SND_SOC_DAPM_DAC("Left DAC", "HIFI Playback",
9418c2ecf20Sopenharmony_ci		RT5631_PWR_MANAG_ADD1, RT5631_PWR_DAC_L_CLK_BIT, 0),
9428c2ecf20Sopenharmony_ci	SND_SOC_DAPM_DAC("Right DAC", "HIFI Playback",
9438c2ecf20Sopenharmony_ci		RT5631_PWR_MANAG_ADD1, RT5631_PWR_DAC_R_CLK_BIT, 0),
9448c2ecf20Sopenharmony_ci	SND_SOC_DAPM_DAC("Voice DAC", "Voice DAC Mono Playback",
9458c2ecf20Sopenharmony_ci				SND_SOC_NOPM, 0, 0),
9468c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("Voice DAC Boost", SND_SOC_NOPM, 0, 0, NULL, 0),
9478c2ecf20Sopenharmony_ci	/* DAC supply power */
9488c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("Left DAC To Mixer", RT5631_PWR_MANAG_ADD1,
9498c2ecf20Sopenharmony_ci			RT5631_PWR_DAC_L_TO_MIXER_BIT, 0, NULL, 0),
9508c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("Right DAC To Mixer", RT5631_PWR_MANAG_ADD1,
9518c2ecf20Sopenharmony_ci			RT5631_PWR_DAC_R_TO_MIXER_BIT, 0, NULL, 0),
9528c2ecf20Sopenharmony_ci
9538c2ecf20Sopenharmony_ci	/* Left SPK Mixer */
9548c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("SPKMIXL Mixer", RT5631_PWR_MANAG_ADD2,
9558c2ecf20Sopenharmony_ci			RT5631_PWR_SPKMIXER_L_BIT, 0,
9568c2ecf20Sopenharmony_ci			&rt5631_spkmixl_mixer_controls[0],
9578c2ecf20Sopenharmony_ci			ARRAY_SIZE(rt5631_spkmixl_mixer_controls)),
9588c2ecf20Sopenharmony_ci	/* Left Out Mixer */
9598c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("OUTMIXL Mixer", RT5631_PWR_MANAG_ADD2,
9608c2ecf20Sopenharmony_ci			RT5631_PWR_OUTMIXER_L_BIT, 0,
9618c2ecf20Sopenharmony_ci			&rt5631_outmixl_mixer_controls[0],
9628c2ecf20Sopenharmony_ci			ARRAY_SIZE(rt5631_outmixl_mixer_controls)),
9638c2ecf20Sopenharmony_ci	/* Right Out Mixer */
9648c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("OUTMIXR Mixer", RT5631_PWR_MANAG_ADD2,
9658c2ecf20Sopenharmony_ci			RT5631_PWR_OUTMIXER_R_BIT, 0,
9668c2ecf20Sopenharmony_ci			&rt5631_outmixr_mixer_controls[0],
9678c2ecf20Sopenharmony_ci			ARRAY_SIZE(rt5631_outmixr_mixer_controls)),
9688c2ecf20Sopenharmony_ci	/* Right SPK Mixer */
9698c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("SPKMIXR Mixer", RT5631_PWR_MANAG_ADD2,
9708c2ecf20Sopenharmony_ci			RT5631_PWR_SPKMIXER_R_BIT, 0,
9718c2ecf20Sopenharmony_ci			&rt5631_spkmixr_mixer_controls[0],
9728c2ecf20Sopenharmony_ci			ARRAY_SIZE(rt5631_spkmixr_mixer_controls)),
9738c2ecf20Sopenharmony_ci
9748c2ecf20Sopenharmony_ci	/* Volume Mux */
9758c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("Left SPKVOL Mux", RT5631_PWR_MANAG_ADD4,
9768c2ecf20Sopenharmony_ci			RT5631_PWR_SPK_L_VOL_BIT, 0,
9778c2ecf20Sopenharmony_ci			&rt5631_spkvoll_mux_control),
9788c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("Left HPVOL Mux", RT5631_PWR_MANAG_ADD4,
9798c2ecf20Sopenharmony_ci			RT5631_PWR_HP_L_OUT_VOL_BIT, 0,
9808c2ecf20Sopenharmony_ci			&rt5631_hpvoll_mux_control),
9818c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("Left OUTVOL Mux", RT5631_PWR_MANAG_ADD4,
9828c2ecf20Sopenharmony_ci			RT5631_PWR_LOUT_VOL_BIT, 0,
9838c2ecf20Sopenharmony_ci			&rt5631_outvoll_mux_control),
9848c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("Right OUTVOL Mux", RT5631_PWR_MANAG_ADD4,
9858c2ecf20Sopenharmony_ci			RT5631_PWR_ROUT_VOL_BIT, 0,
9868c2ecf20Sopenharmony_ci			&rt5631_outvolr_mux_control),
9878c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("Right HPVOL Mux", RT5631_PWR_MANAG_ADD4,
9888c2ecf20Sopenharmony_ci			RT5631_PWR_HP_R_OUT_VOL_BIT, 0,
9898c2ecf20Sopenharmony_ci			&rt5631_hpvolr_mux_control),
9908c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("Right SPKVOL Mux", RT5631_PWR_MANAG_ADD4,
9918c2ecf20Sopenharmony_ci			RT5631_PWR_SPK_R_VOL_BIT, 0,
9928c2ecf20Sopenharmony_ci			&rt5631_spkvolr_mux_control),
9938c2ecf20Sopenharmony_ci
9948c2ecf20Sopenharmony_ci	/* DAC To HP */
9958c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA_S("Left DAC_HP", 0, SND_SOC_NOPM, 0, 0, NULL, 0),
9968c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA_S("Right DAC_HP", 0, SND_SOC_NOPM, 0, 0, NULL, 0),
9978c2ecf20Sopenharmony_ci
9988c2ecf20Sopenharmony_ci	/* HP Depop */
9998c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA_S("HP Depop", 1, SND_SOC_NOPM, 0, 0,
10008c2ecf20Sopenharmony_ci		hp_event, SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
10018c2ecf20Sopenharmony_ci
10028c2ecf20Sopenharmony_ci	/* AXO1 Mixer */
10038c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("AXO1MIX Mixer", RT5631_PWR_MANAG_ADD3,
10048c2ecf20Sopenharmony_ci			RT5631_PWR_AXO1MIXER_BIT, 0,
10058c2ecf20Sopenharmony_ci			&rt5631_AXO1MIX_mixer_controls[0],
10068c2ecf20Sopenharmony_ci			ARRAY_SIZE(rt5631_AXO1MIX_mixer_controls)),
10078c2ecf20Sopenharmony_ci	/* SPOL Mixer */
10088c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("SPOLMIX Mixer", SND_SOC_NOPM, 0, 0,
10098c2ecf20Sopenharmony_ci			&rt5631_spolmix_mixer_controls[0],
10108c2ecf20Sopenharmony_ci			ARRAY_SIZE(rt5631_spolmix_mixer_controls)),
10118c2ecf20Sopenharmony_ci	/* MONO Mixer */
10128c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("MONOMIX Mixer", RT5631_PWR_MANAG_ADD3,
10138c2ecf20Sopenharmony_ci			RT5631_PWR_MONOMIXER_BIT, 0,
10148c2ecf20Sopenharmony_ci			&rt5631_monomix_mixer_controls[0],
10158c2ecf20Sopenharmony_ci			ARRAY_SIZE(rt5631_monomix_mixer_controls)),
10168c2ecf20Sopenharmony_ci	/* SPOR Mixer */
10178c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("SPORMIX Mixer", SND_SOC_NOPM, 0, 0,
10188c2ecf20Sopenharmony_ci			&rt5631_spormix_mixer_controls[0],
10198c2ecf20Sopenharmony_ci			ARRAY_SIZE(rt5631_spormix_mixer_controls)),
10208c2ecf20Sopenharmony_ci	/* AXO2 Mixer */
10218c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("AXO2MIX Mixer", RT5631_PWR_MANAG_ADD3,
10228c2ecf20Sopenharmony_ci			RT5631_PWR_AXO2MIXER_BIT, 0,
10238c2ecf20Sopenharmony_ci			&rt5631_AXO2MIX_mixer_controls[0],
10248c2ecf20Sopenharmony_ci			ARRAY_SIZE(rt5631_AXO2MIX_mixer_controls)),
10258c2ecf20Sopenharmony_ci
10268c2ecf20Sopenharmony_ci	/* Mux */
10278c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("SPOL Mux", SND_SOC_NOPM, 0, 0,
10288c2ecf20Sopenharmony_ci			&rt5631_spol_mux_control),
10298c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("SPOR Mux", SND_SOC_NOPM, 0, 0,
10308c2ecf20Sopenharmony_ci			&rt5631_spor_mux_control),
10318c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("MONO Mux", SND_SOC_NOPM, 0, 0,
10328c2ecf20Sopenharmony_ci			&rt5631_mono_mux_control),
10338c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("HPL Mux", SND_SOC_NOPM, 0, 0,
10348c2ecf20Sopenharmony_ci			&rt5631_hpl_mux_control),
10358c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("HPR Mux", SND_SOC_NOPM, 0, 0,
10368c2ecf20Sopenharmony_ci			&rt5631_hpr_mux_control),
10378c2ecf20Sopenharmony_ci
10388c2ecf20Sopenharmony_ci	/* AMP supply */
10398c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MONO Depop", RT5631_PWR_MANAG_ADD3,
10408c2ecf20Sopenharmony_ci			RT5631_PWR_MONO_DEPOP_DIS_BIT, 0, NULL, 0),
10418c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("Class D", RT5631_PWR_MANAG_ADD1,
10428c2ecf20Sopenharmony_ci			RT5631_PWR_CLASS_D_BIT, 0, NULL, 0),
10438c2ecf20Sopenharmony_ci
10448c2ecf20Sopenharmony_ci	/* Output Lines */
10458c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("AUXO1"),
10468c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("AUXO2"),
10478c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("SPOL"),
10488c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("SPOR"),
10498c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("HPOL"),
10508c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("HPOR"),
10518c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("MONO"),
10528c2ecf20Sopenharmony_ci};
10538c2ecf20Sopenharmony_ci
10548c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route rt5631_dapm_routes[] = {
10558c2ecf20Sopenharmony_ci	{"MIC1 Boost", NULL, "MIC1"},
10568c2ecf20Sopenharmony_ci	{"MIC2 Boost", NULL, "MIC2"},
10578c2ecf20Sopenharmony_ci	{"MONOIN_RXP Boost", NULL, "MONOIN_RXP"},
10588c2ecf20Sopenharmony_ci	{"MONOIN_RXN Boost", NULL, "MONOIN_RXN"},
10598c2ecf20Sopenharmony_ci	{"AXIL Boost", NULL, "AXIL"},
10608c2ecf20Sopenharmony_ci	{"AXIR Boost", NULL, "AXIR"},
10618c2ecf20Sopenharmony_ci
10628c2ecf20Sopenharmony_ci	{"MONO_IN", NULL, "MONOIN_RXP Boost"},
10638c2ecf20Sopenharmony_ci	{"MONO_IN", NULL, "MONOIN_RXN Boost"},
10648c2ecf20Sopenharmony_ci
10658c2ecf20Sopenharmony_ci	{"RECMIXL Mixer", "OUTMIXL Capture Switch", "OUTMIXL Mixer"},
10668c2ecf20Sopenharmony_ci	{"RECMIXL Mixer", "MIC1_BST1 Capture Switch", "MIC1 Boost"},
10678c2ecf20Sopenharmony_ci	{"RECMIXL Mixer", "AXILVOL Capture Switch", "AXIL Boost"},
10688c2ecf20Sopenharmony_ci	{"RECMIXL Mixer", "MONOIN_RX Capture Switch", "MONO_IN"},
10698c2ecf20Sopenharmony_ci
10708c2ecf20Sopenharmony_ci	{"RECMIXR Mixer", "OUTMIXR Capture Switch", "OUTMIXR Mixer"},
10718c2ecf20Sopenharmony_ci	{"RECMIXR Mixer", "MIC2_BST2 Capture Switch", "MIC2 Boost"},
10728c2ecf20Sopenharmony_ci	{"RECMIXR Mixer", "AXIRVOL Capture Switch", "AXIR Boost"},
10738c2ecf20Sopenharmony_ci	{"RECMIXR Mixer", "MONOIN_RX Capture Switch", "MONO_IN"},
10748c2ecf20Sopenharmony_ci
10758c2ecf20Sopenharmony_ci	{"ADC Mixer", NULL, "RECMIXL Mixer"},
10768c2ecf20Sopenharmony_ci	{"ADC Mixer", NULL, "RECMIXR Mixer"},
10778c2ecf20Sopenharmony_ci
10788c2ecf20Sopenharmony_ci	{"Left ADC", NULL, "ADC Mixer"},
10798c2ecf20Sopenharmony_ci	{"Left ADC", NULL, "Left ADC Select", check_adcl_select},
10808c2ecf20Sopenharmony_ci	{"Left ADC", NULL, "PLL1", check_sysclk1_source},
10818c2ecf20Sopenharmony_ci	{"Left ADC", NULL, "I2S"},
10828c2ecf20Sopenharmony_ci	{"Left ADC", NULL, "DAC REF"},
10838c2ecf20Sopenharmony_ci
10848c2ecf20Sopenharmony_ci	{"Right ADC", NULL, "ADC Mixer"},
10858c2ecf20Sopenharmony_ci	{"Right ADC", NULL, "Right ADC Select", check_adcr_select},
10868c2ecf20Sopenharmony_ci	{"Right ADC", NULL, "PLL1", check_sysclk1_source},
10878c2ecf20Sopenharmony_ci	{"Right ADC", NULL, "I2S"},
10888c2ecf20Sopenharmony_ci	{"Right ADC", NULL, "DAC REF"},
10898c2ecf20Sopenharmony_ci
10908c2ecf20Sopenharmony_ci	{"DMIC", NULL, "DMIC Supply", check_dmic_used},
10918c2ecf20Sopenharmony_ci	{"Left ADC", NULL, "DMIC"},
10928c2ecf20Sopenharmony_ci	{"Right ADC", NULL, "DMIC"},
10938c2ecf20Sopenharmony_ci
10948c2ecf20Sopenharmony_ci	{"Left DAC", NULL, "PLL1", check_sysclk1_source},
10958c2ecf20Sopenharmony_ci	{"Left DAC", NULL, "I2S"},
10968c2ecf20Sopenharmony_ci	{"Left DAC", NULL, "DAC REF"},
10978c2ecf20Sopenharmony_ci	{"Right DAC", NULL, "PLL1", check_sysclk1_source},
10988c2ecf20Sopenharmony_ci	{"Right DAC", NULL, "I2S"},
10998c2ecf20Sopenharmony_ci	{"Right DAC", NULL, "DAC REF"},
11008c2ecf20Sopenharmony_ci
11018c2ecf20Sopenharmony_ci	{"Voice DAC Boost", NULL, "Voice DAC"},
11028c2ecf20Sopenharmony_ci
11038c2ecf20Sopenharmony_ci	{"SPKMIXL Mixer", NULL, "Left DAC To Mixer", check_dacl_to_spkmixl},
11048c2ecf20Sopenharmony_ci	{"SPKMIXL Mixer", "RECMIXL Playback Switch", "RECMIXL Mixer"},
11058c2ecf20Sopenharmony_ci	{"SPKMIXL Mixer", "MIC1_P Playback Switch", "MIC1"},
11068c2ecf20Sopenharmony_ci	{"SPKMIXL Mixer", "DACL Playback Switch", "Left DAC"},
11078c2ecf20Sopenharmony_ci	{"SPKMIXL Mixer", "OUTMIXL Playback Switch", "OUTMIXL Mixer"},
11088c2ecf20Sopenharmony_ci
11098c2ecf20Sopenharmony_ci	{"SPKMIXR Mixer", NULL, "Right DAC To Mixer", check_dacr_to_spkmixr},
11108c2ecf20Sopenharmony_ci	{"SPKMIXR Mixer", "OUTMIXR Playback Switch", "OUTMIXR Mixer"},
11118c2ecf20Sopenharmony_ci	{"SPKMIXR Mixer", "DACR Playback Switch", "Right DAC"},
11128c2ecf20Sopenharmony_ci	{"SPKMIXR Mixer", "MIC2_P Playback Switch", "MIC2"},
11138c2ecf20Sopenharmony_ci	{"SPKMIXR Mixer", "RECMIXR Playback Switch", "RECMIXR Mixer"},
11148c2ecf20Sopenharmony_ci
11158c2ecf20Sopenharmony_ci	{"OUTMIXL Mixer", NULL, "Left DAC To Mixer", check_dacl_to_outmixl},
11168c2ecf20Sopenharmony_ci	{"OUTMIXL Mixer", "RECMIXL Playback Switch", "RECMIXL Mixer"},
11178c2ecf20Sopenharmony_ci	{"OUTMIXL Mixer", "RECMIXR Playback Switch", "RECMIXR Mixer"},
11188c2ecf20Sopenharmony_ci	{"OUTMIXL Mixer", "DACL Playback Switch", "Left DAC"},
11198c2ecf20Sopenharmony_ci	{"OUTMIXL Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
11208c2ecf20Sopenharmony_ci	{"OUTMIXL Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
11218c2ecf20Sopenharmony_ci	{"OUTMIXL Mixer", "MONOIN_RXP Playback Switch", "MONOIN_RXP Boost"},
11228c2ecf20Sopenharmony_ci	{"OUTMIXL Mixer", "AXILVOL Playback Switch", "AXIL Boost"},
11238c2ecf20Sopenharmony_ci	{"OUTMIXL Mixer", "AXIRVOL Playback Switch", "AXIR Boost"},
11248c2ecf20Sopenharmony_ci	{"OUTMIXL Mixer", "VDAC Playback Switch", "Voice DAC Boost"},
11258c2ecf20Sopenharmony_ci
11268c2ecf20Sopenharmony_ci	{"OUTMIXR Mixer", NULL, "Right DAC To Mixer", check_dacr_to_outmixr},
11278c2ecf20Sopenharmony_ci	{"OUTMIXR Mixer", "RECMIXL Playback Switch", "RECMIXL Mixer"},
11288c2ecf20Sopenharmony_ci	{"OUTMIXR Mixer", "RECMIXR Playback Switch", "RECMIXR Mixer"},
11298c2ecf20Sopenharmony_ci	{"OUTMIXR Mixer", "DACR Playback Switch", "Right DAC"},
11308c2ecf20Sopenharmony_ci	{"OUTMIXR Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
11318c2ecf20Sopenharmony_ci	{"OUTMIXR Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
11328c2ecf20Sopenharmony_ci	{"OUTMIXR Mixer", "MONOIN_RXN Playback Switch", "MONOIN_RXN Boost"},
11338c2ecf20Sopenharmony_ci	{"OUTMIXR Mixer", "AXILVOL Playback Switch", "AXIL Boost"},
11348c2ecf20Sopenharmony_ci	{"OUTMIXR Mixer", "AXIRVOL Playback Switch", "AXIR Boost"},
11358c2ecf20Sopenharmony_ci	{"OUTMIXR Mixer", "VDAC Playback Switch", "Voice DAC Boost"},
11368c2ecf20Sopenharmony_ci
11378c2ecf20Sopenharmony_ci	{"Left SPKVOL Mux",  "SPKMIXL", "SPKMIXL Mixer"},
11388c2ecf20Sopenharmony_ci	{"Left SPKVOL Mux",  "Vmid", "Vmid"},
11398c2ecf20Sopenharmony_ci	{"Left HPVOL Mux",  "OUTMIXL", "OUTMIXL Mixer"},
11408c2ecf20Sopenharmony_ci	{"Left HPVOL Mux",  "Vmid", "Vmid"},
11418c2ecf20Sopenharmony_ci	{"Left OUTVOL Mux",  "OUTMIXL", "OUTMIXL Mixer"},
11428c2ecf20Sopenharmony_ci	{"Left OUTVOL Mux",  "Vmid", "Vmid"},
11438c2ecf20Sopenharmony_ci	{"Right OUTVOL Mux",  "OUTMIXR", "OUTMIXR Mixer"},
11448c2ecf20Sopenharmony_ci	{"Right OUTVOL Mux",  "Vmid", "Vmid"},
11458c2ecf20Sopenharmony_ci	{"Right HPVOL Mux",  "OUTMIXR", "OUTMIXR Mixer"},
11468c2ecf20Sopenharmony_ci	{"Right HPVOL Mux",  "Vmid", "Vmid"},
11478c2ecf20Sopenharmony_ci	{"Right SPKVOL Mux",  "SPKMIXR", "SPKMIXR Mixer"},
11488c2ecf20Sopenharmony_ci	{"Right SPKVOL Mux",  "Vmid", "Vmid"},
11498c2ecf20Sopenharmony_ci
11508c2ecf20Sopenharmony_ci	{"AXO1MIX Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
11518c2ecf20Sopenharmony_ci	{"AXO1MIX Mixer", "OUTVOLL Playback Switch", "Left OUTVOL Mux"},
11528c2ecf20Sopenharmony_ci	{"AXO1MIX Mixer", "OUTVOLR Playback Switch", "Right OUTVOL Mux"},
11538c2ecf20Sopenharmony_ci	{"AXO1MIX Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci	{"AXO2MIX Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
11568c2ecf20Sopenharmony_ci	{"AXO2MIX Mixer", "OUTVOLL Playback Switch", "Left OUTVOL Mux"},
11578c2ecf20Sopenharmony_ci	{"AXO2MIX Mixer", "OUTVOLR Playback Switch", "Right OUTVOL Mux"},
11588c2ecf20Sopenharmony_ci	{"AXO2MIX Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
11598c2ecf20Sopenharmony_ci
11608c2ecf20Sopenharmony_ci	{"SPOLMIX Mixer", "SPKVOLL Playback Switch", "Left SPKVOL Mux"},
11618c2ecf20Sopenharmony_ci	{"SPOLMIX Mixer", "SPKVOLR Playback Switch", "Right SPKVOL Mux"},
11628c2ecf20Sopenharmony_ci
11638c2ecf20Sopenharmony_ci	{"SPORMIX Mixer", "SPKVOLL Playback Switch", "Left SPKVOL Mux"},
11648c2ecf20Sopenharmony_ci	{"SPORMIX Mixer", "SPKVOLR Playback Switch", "Right SPKVOL Mux"},
11658c2ecf20Sopenharmony_ci
11668c2ecf20Sopenharmony_ci	{"MONOMIX Mixer", "OUTVOLL Playback Switch", "Left OUTVOL Mux"},
11678c2ecf20Sopenharmony_ci	{"MONOMIX Mixer", "OUTVOLR Playback Switch", "Right OUTVOL Mux"},
11688c2ecf20Sopenharmony_ci
11698c2ecf20Sopenharmony_ci	{"SPOL Mux", "SPOLMIX", "SPOLMIX Mixer"},
11708c2ecf20Sopenharmony_ci	{"SPOL Mux", "MONOIN_RX", "MONO_IN"},
11718c2ecf20Sopenharmony_ci	{"SPOL Mux", "VDAC", "Voice DAC Boost"},
11728c2ecf20Sopenharmony_ci	{"SPOL Mux", "DACL", "Left DAC"},
11738c2ecf20Sopenharmony_ci
11748c2ecf20Sopenharmony_ci	{"SPOR Mux", "SPORMIX", "SPORMIX Mixer"},
11758c2ecf20Sopenharmony_ci	{"SPOR Mux", "MONOIN_RX", "MONO_IN"},
11768c2ecf20Sopenharmony_ci	{"SPOR Mux", "VDAC", "Voice DAC Boost"},
11778c2ecf20Sopenharmony_ci	{"SPOR Mux", "DACR", "Right DAC"},
11788c2ecf20Sopenharmony_ci
11798c2ecf20Sopenharmony_ci	{"MONO Mux", "MONOMIX", "MONOMIX Mixer"},
11808c2ecf20Sopenharmony_ci	{"MONO Mux", "MONOIN_RX", "MONO_IN"},
11818c2ecf20Sopenharmony_ci	{"MONO Mux", "VDAC", "Voice DAC Boost"},
11828c2ecf20Sopenharmony_ci
11838c2ecf20Sopenharmony_ci	{"Right DAC_HP", NULL, "Right DAC"},
11848c2ecf20Sopenharmony_ci	{"Left DAC_HP", NULL, "Left DAC"},
11858c2ecf20Sopenharmony_ci
11868c2ecf20Sopenharmony_ci	{"HPL Mux", "Left HPVOL", "Left HPVOL Mux"},
11878c2ecf20Sopenharmony_ci	{"HPL Mux", "Left DAC", "Left DAC_HP"},
11888c2ecf20Sopenharmony_ci	{"HPR Mux", "Right HPVOL", "Right HPVOL Mux"},
11898c2ecf20Sopenharmony_ci	{"HPR Mux", "Right DAC", "Right DAC_HP"},
11908c2ecf20Sopenharmony_ci
11918c2ecf20Sopenharmony_ci	{"HP Depop", NULL, "HPL Mux"},
11928c2ecf20Sopenharmony_ci	{"HP Depop", NULL, "HPR Mux"},
11938c2ecf20Sopenharmony_ci
11948c2ecf20Sopenharmony_ci	{"AUXO1", NULL, "AXO1MIX Mixer"},
11958c2ecf20Sopenharmony_ci	{"AUXO2", NULL, "AXO2MIX Mixer"},
11968c2ecf20Sopenharmony_ci
11978c2ecf20Sopenharmony_ci	{"SPOL", NULL, "Class D"},
11988c2ecf20Sopenharmony_ci	{"SPOL", NULL, "SPOL Mux"},
11998c2ecf20Sopenharmony_ci	{"SPOR", NULL, "Class D"},
12008c2ecf20Sopenharmony_ci	{"SPOR", NULL, "SPOR Mux"},
12018c2ecf20Sopenharmony_ci
12028c2ecf20Sopenharmony_ci	{"HPOL", NULL, "HP Depop"},
12038c2ecf20Sopenharmony_ci	{"HPOR", NULL, "HP Depop"},
12048c2ecf20Sopenharmony_ci
12058c2ecf20Sopenharmony_ci	{"MONO", NULL, "MONO Depop"},
12068c2ecf20Sopenharmony_ci	{"MONO", NULL, "MONO Mux"},
12078c2ecf20Sopenharmony_ci};
12088c2ecf20Sopenharmony_ci
12098c2ecf20Sopenharmony_cistruct coeff_clk_div {
12108c2ecf20Sopenharmony_ci	u32 mclk;
12118c2ecf20Sopenharmony_ci	u32 bclk;
12128c2ecf20Sopenharmony_ci	u32 rate;
12138c2ecf20Sopenharmony_ci	u16 reg_val;
12148c2ecf20Sopenharmony_ci};
12158c2ecf20Sopenharmony_ci
12168c2ecf20Sopenharmony_ci/* PLL divisors */
12178c2ecf20Sopenharmony_cistruct pll_div {
12188c2ecf20Sopenharmony_ci	u32 pll_in;
12198c2ecf20Sopenharmony_ci	u32 pll_out;
12208c2ecf20Sopenharmony_ci	u16 reg_val;
12218c2ecf20Sopenharmony_ci};
12228c2ecf20Sopenharmony_ci
12238c2ecf20Sopenharmony_cistatic const struct pll_div codec_master_pll_div[] = {
12248c2ecf20Sopenharmony_ci	{2048000,  8192000,  0x0ea0},
12258c2ecf20Sopenharmony_ci	{3686400,  8192000,  0x4e27},
12268c2ecf20Sopenharmony_ci	{12000000,  8192000,  0x456b},
12278c2ecf20Sopenharmony_ci	{13000000,  8192000,  0x495f},
12288c2ecf20Sopenharmony_ci	{13100000,  8192000,  0x0320},
12298c2ecf20Sopenharmony_ci	{2048000,  11289600,  0xf637},
12308c2ecf20Sopenharmony_ci	{3686400,  11289600,  0x2f22},
12318c2ecf20Sopenharmony_ci	{12000000,  11289600,  0x3e2f},
12328c2ecf20Sopenharmony_ci	{13000000,  11289600,  0x4d5b},
12338c2ecf20Sopenharmony_ci	{13100000,  11289600,  0x363b},
12348c2ecf20Sopenharmony_ci	{2048000,  16384000,  0x1ea0},
12358c2ecf20Sopenharmony_ci	{3686400,  16384000,  0x9e27},
12368c2ecf20Sopenharmony_ci	{12000000,  16384000,  0x452b},
12378c2ecf20Sopenharmony_ci	{13000000,  16384000,  0x542f},
12388c2ecf20Sopenharmony_ci	{13100000,  16384000,  0x03a0},
12398c2ecf20Sopenharmony_ci	{2048000,  16934400,  0xe625},
12408c2ecf20Sopenharmony_ci	{3686400,  16934400,  0x9126},
12418c2ecf20Sopenharmony_ci	{12000000,  16934400,  0x4d2c},
12428c2ecf20Sopenharmony_ci	{13000000,  16934400,  0x742f},
12438c2ecf20Sopenharmony_ci	{13100000,  16934400,  0x3c27},
12448c2ecf20Sopenharmony_ci	{2048000,  22579200,  0x2aa0},
12458c2ecf20Sopenharmony_ci	{3686400,  22579200,  0x2f20},
12468c2ecf20Sopenharmony_ci	{12000000,  22579200,  0x7e2f},
12478c2ecf20Sopenharmony_ci	{13000000,  22579200,  0x742f},
12488c2ecf20Sopenharmony_ci	{13100000,  22579200,  0x3c27},
12498c2ecf20Sopenharmony_ci	{2048000,  24576000,  0x2ea0},
12508c2ecf20Sopenharmony_ci	{3686400,  24576000,  0xee27},
12518c2ecf20Sopenharmony_ci	{12000000,  24576000,  0x2915},
12528c2ecf20Sopenharmony_ci	{13000000,  24576000,  0x772e},
12538c2ecf20Sopenharmony_ci	{13100000,  24576000,  0x0d20},
12548c2ecf20Sopenharmony_ci	{26000000,  24576000,  0x2027},
12558c2ecf20Sopenharmony_ci	{26000000,  22579200,  0x392f},
12568c2ecf20Sopenharmony_ci	{24576000,  22579200,  0x0921},
12578c2ecf20Sopenharmony_ci	{24576000,  24576000,  0x02a0},
12588c2ecf20Sopenharmony_ci};
12598c2ecf20Sopenharmony_ci
12608c2ecf20Sopenharmony_cistatic const struct pll_div codec_slave_pll_div[] = {
12618c2ecf20Sopenharmony_ci	{256000,  2048000,  0x46f0},
12628c2ecf20Sopenharmony_ci	{256000,  4096000,  0x3ea0},
12638c2ecf20Sopenharmony_ci	{352800,  5644800,  0x3ea0},
12648c2ecf20Sopenharmony_ci	{512000,  8192000,  0x3ea0},
12658c2ecf20Sopenharmony_ci	{1024000,  8192000,  0x46f0},
12668c2ecf20Sopenharmony_ci	{705600,  11289600,  0x3ea0},
12678c2ecf20Sopenharmony_ci	{1024000,  16384000,  0x3ea0},
12688c2ecf20Sopenharmony_ci	{1411200,  22579200,  0x3ea0},
12698c2ecf20Sopenharmony_ci	{1536000,  24576000,  0x3ea0},
12708c2ecf20Sopenharmony_ci	{2048000,  16384000,  0x1ea0},
12718c2ecf20Sopenharmony_ci	{2822400,  22579200,  0x1ea0},
12728c2ecf20Sopenharmony_ci	{2822400,  45158400,  0x5ec0},
12738c2ecf20Sopenharmony_ci	{5644800,  45158400,  0x46f0},
12748c2ecf20Sopenharmony_ci	{3072000,  24576000,  0x1ea0},
12758c2ecf20Sopenharmony_ci	{3072000,  49152000,  0x5ec0},
12768c2ecf20Sopenharmony_ci	{6144000,  49152000,  0x46f0},
12778c2ecf20Sopenharmony_ci	{705600,  11289600,  0x3ea0},
12788c2ecf20Sopenharmony_ci	{705600,  8467200,  0x3ab0},
12798c2ecf20Sopenharmony_ci	{24576000,  24576000,  0x02a0},
12808c2ecf20Sopenharmony_ci	{1411200,  11289600,  0x1690},
12818c2ecf20Sopenharmony_ci	{2822400,  11289600,  0x0a90},
12828c2ecf20Sopenharmony_ci	{1536000,  12288000,  0x1690},
12838c2ecf20Sopenharmony_ci	{3072000,  12288000,  0x0a90},
12848c2ecf20Sopenharmony_ci};
12858c2ecf20Sopenharmony_ci
12868c2ecf20Sopenharmony_cistatic struct coeff_clk_div coeff_div[] = {
12878c2ecf20Sopenharmony_ci	/* sysclk is 256fs */
12888c2ecf20Sopenharmony_ci	{2048000,  8000 * 32,  8000, 0x1000},
12898c2ecf20Sopenharmony_ci	{2048000,  8000 * 64,  8000, 0x0000},
12908c2ecf20Sopenharmony_ci	{2822400,  11025 * 32,  11025,  0x1000},
12918c2ecf20Sopenharmony_ci	{2822400,  11025 * 64,  11025,  0x0000},
12928c2ecf20Sopenharmony_ci	{4096000,  16000 * 32,  16000,  0x1000},
12938c2ecf20Sopenharmony_ci	{4096000,  16000 * 64,  16000,  0x0000},
12948c2ecf20Sopenharmony_ci	{5644800,  22050 * 32,  22050,  0x1000},
12958c2ecf20Sopenharmony_ci	{5644800,  22050 * 64,  22050,  0x0000},
12968c2ecf20Sopenharmony_ci	{8192000,  32000 * 32,  32000,  0x1000},
12978c2ecf20Sopenharmony_ci	{8192000,  32000 * 64,  32000,  0x0000},
12988c2ecf20Sopenharmony_ci	{11289600,  44100 * 32,  44100,  0x1000},
12998c2ecf20Sopenharmony_ci	{11289600,  44100 * 64,  44100,  0x0000},
13008c2ecf20Sopenharmony_ci	{12288000,  48000 * 32,  48000,  0x1000},
13018c2ecf20Sopenharmony_ci	{12288000,  48000 * 64,  48000,  0x0000},
13028c2ecf20Sopenharmony_ci	{22579200,  88200 * 32,  88200,  0x1000},
13038c2ecf20Sopenharmony_ci	{22579200,  88200 * 64,  88200,  0x0000},
13048c2ecf20Sopenharmony_ci	{24576000,  96000 * 32,  96000,  0x1000},
13058c2ecf20Sopenharmony_ci	{24576000,  96000 * 64,  96000,  0x0000},
13068c2ecf20Sopenharmony_ci	/* sysclk is 512fs */
13078c2ecf20Sopenharmony_ci	{4096000,  8000 * 32,  8000, 0x3000},
13088c2ecf20Sopenharmony_ci	{4096000,  8000 * 64,  8000, 0x2000},
13098c2ecf20Sopenharmony_ci	{5644800,  11025 * 32,  11025, 0x3000},
13108c2ecf20Sopenharmony_ci	{5644800,  11025 * 64,  11025, 0x2000},
13118c2ecf20Sopenharmony_ci	{8192000,  16000 * 32,  16000, 0x3000},
13128c2ecf20Sopenharmony_ci	{8192000,  16000 * 64,  16000, 0x2000},
13138c2ecf20Sopenharmony_ci	{11289600,  22050 * 32,  22050, 0x3000},
13148c2ecf20Sopenharmony_ci	{11289600,  22050 * 64,  22050, 0x2000},
13158c2ecf20Sopenharmony_ci	{16384000,  32000 * 32,  32000, 0x3000},
13168c2ecf20Sopenharmony_ci	{16384000,  32000 * 64,  32000, 0x2000},
13178c2ecf20Sopenharmony_ci	{22579200,  44100 * 32,  44100, 0x3000},
13188c2ecf20Sopenharmony_ci	{22579200,  44100 * 64,  44100, 0x2000},
13198c2ecf20Sopenharmony_ci	{24576000,  48000 * 32,  48000, 0x3000},
13208c2ecf20Sopenharmony_ci	{24576000,  48000 * 64,  48000, 0x2000},
13218c2ecf20Sopenharmony_ci	{45158400,  88200 * 32,  88200, 0x3000},
13228c2ecf20Sopenharmony_ci	{45158400,  88200 * 64,  88200, 0x2000},
13238c2ecf20Sopenharmony_ci	{49152000,  96000 * 32,  96000, 0x3000},
13248c2ecf20Sopenharmony_ci	{49152000,  96000 * 64,  96000, 0x2000},
13258c2ecf20Sopenharmony_ci	/* sysclk is 24.576Mhz or 22.5792Mhz */
13268c2ecf20Sopenharmony_ci	{24576000,  8000 * 32,  8000,  0x7080},
13278c2ecf20Sopenharmony_ci	{24576000,  8000 * 64,  8000,  0x6080},
13288c2ecf20Sopenharmony_ci	{24576000,  16000 * 32,  16000,  0x5080},
13298c2ecf20Sopenharmony_ci	{24576000,  16000 * 64,  16000,  0x4080},
13308c2ecf20Sopenharmony_ci	{24576000,  24000 * 32,  24000,  0x5000},
13318c2ecf20Sopenharmony_ci	{24576000,  24000 * 64,  24000,  0x4000},
13328c2ecf20Sopenharmony_ci	{24576000,  32000 * 32,  32000,  0x3080},
13338c2ecf20Sopenharmony_ci	{24576000,  32000 * 64,  32000,  0x2080},
13348c2ecf20Sopenharmony_ci	{22579200,  11025 * 32,  11025,  0x7000},
13358c2ecf20Sopenharmony_ci	{22579200,  11025 * 64,  11025,  0x6000},
13368c2ecf20Sopenharmony_ci	{22579200,  22050 * 32,  22050,  0x5000},
13378c2ecf20Sopenharmony_ci	{22579200,  22050 * 64,  22050,  0x4000},
13388c2ecf20Sopenharmony_ci};
13398c2ecf20Sopenharmony_ci
13408c2ecf20Sopenharmony_cistatic int get_coeff(int mclk, int rate, int timesofbclk)
13418c2ecf20Sopenharmony_ci{
13428c2ecf20Sopenharmony_ci	int i;
13438c2ecf20Sopenharmony_ci
13448c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
13458c2ecf20Sopenharmony_ci		if (coeff_div[i].mclk == mclk && coeff_div[i].rate == rate &&
13468c2ecf20Sopenharmony_ci			(coeff_div[i].bclk / coeff_div[i].rate) == timesofbclk)
13478c2ecf20Sopenharmony_ci			return i;
13488c2ecf20Sopenharmony_ci	}
13498c2ecf20Sopenharmony_ci	return -EINVAL;
13508c2ecf20Sopenharmony_ci}
13518c2ecf20Sopenharmony_ci
13528c2ecf20Sopenharmony_cistatic int rt5631_hifi_pcm_params(struct snd_pcm_substream *substream,
13538c2ecf20Sopenharmony_ci		struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
13548c2ecf20Sopenharmony_ci{
13558c2ecf20Sopenharmony_ci	struct snd_soc_component *component = dai->component;
13568c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
13578c2ecf20Sopenharmony_ci	int timesofbclk = 32, coeff;
13588c2ecf20Sopenharmony_ci	unsigned int iface = 0;
13598c2ecf20Sopenharmony_ci
13608c2ecf20Sopenharmony_ci	dev_dbg(component->dev, "enter %s\n", __func__);
13618c2ecf20Sopenharmony_ci
13628c2ecf20Sopenharmony_ci	rt5631->bclk_rate = snd_soc_params_to_bclk(params);
13638c2ecf20Sopenharmony_ci	if (rt5631->bclk_rate < 0) {
13648c2ecf20Sopenharmony_ci		dev_err(component->dev, "Fail to get BCLK rate\n");
13658c2ecf20Sopenharmony_ci		return rt5631->bclk_rate;
13668c2ecf20Sopenharmony_ci	}
13678c2ecf20Sopenharmony_ci	rt5631->rx_rate = params_rate(params);
13688c2ecf20Sopenharmony_ci
13698c2ecf20Sopenharmony_ci	if (rt5631->master)
13708c2ecf20Sopenharmony_ci		coeff = get_coeff(rt5631->sysclk, rt5631->rx_rate,
13718c2ecf20Sopenharmony_ci			rt5631->bclk_rate / rt5631->rx_rate);
13728c2ecf20Sopenharmony_ci	else
13738c2ecf20Sopenharmony_ci		coeff = get_coeff(rt5631->sysclk, rt5631->rx_rate,
13748c2ecf20Sopenharmony_ci					timesofbclk);
13758c2ecf20Sopenharmony_ci	if (coeff < 0) {
13768c2ecf20Sopenharmony_ci		dev_err(component->dev, "Fail to get coeff\n");
13778c2ecf20Sopenharmony_ci		return coeff;
13788c2ecf20Sopenharmony_ci	}
13798c2ecf20Sopenharmony_ci
13808c2ecf20Sopenharmony_ci	switch (params_width(params)) {
13818c2ecf20Sopenharmony_ci	case 16:
13828c2ecf20Sopenharmony_ci		break;
13838c2ecf20Sopenharmony_ci	case 20:
13848c2ecf20Sopenharmony_ci		iface |= RT5631_SDP_I2S_DL_20;
13858c2ecf20Sopenharmony_ci		break;
13868c2ecf20Sopenharmony_ci	case 24:
13878c2ecf20Sopenharmony_ci		iface |= RT5631_SDP_I2S_DL_24;
13888c2ecf20Sopenharmony_ci		break;
13898c2ecf20Sopenharmony_ci	case 8:
13908c2ecf20Sopenharmony_ci		iface |= RT5631_SDP_I2S_DL_8;
13918c2ecf20Sopenharmony_ci		break;
13928c2ecf20Sopenharmony_ci	default:
13938c2ecf20Sopenharmony_ci		return -EINVAL;
13948c2ecf20Sopenharmony_ci	}
13958c2ecf20Sopenharmony_ci
13968c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, RT5631_SDP_CTRL,
13978c2ecf20Sopenharmony_ci		RT5631_SDP_I2S_DL_MASK, iface);
13988c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_STEREO_AD_DA_CLK_CTRL,
13998c2ecf20Sopenharmony_ci					coeff_div[coeff].reg_val);
14008c2ecf20Sopenharmony_ci
14018c2ecf20Sopenharmony_ci	return 0;
14028c2ecf20Sopenharmony_ci}
14038c2ecf20Sopenharmony_ci
14048c2ecf20Sopenharmony_cistatic int rt5631_hifi_codec_set_dai_fmt(struct snd_soc_dai *codec_dai,
14058c2ecf20Sopenharmony_ci						unsigned int fmt)
14068c2ecf20Sopenharmony_ci{
14078c2ecf20Sopenharmony_ci	struct snd_soc_component *component = codec_dai->component;
14088c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
14098c2ecf20Sopenharmony_ci	unsigned int iface = 0;
14108c2ecf20Sopenharmony_ci
14118c2ecf20Sopenharmony_ci	dev_dbg(component->dev, "enter %s\n", __func__);
14128c2ecf20Sopenharmony_ci
14138c2ecf20Sopenharmony_ci	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
14148c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_CBM_CFM:
14158c2ecf20Sopenharmony_ci		rt5631->master = 1;
14168c2ecf20Sopenharmony_ci		break;
14178c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_CBS_CFS:
14188c2ecf20Sopenharmony_ci		iface |= RT5631_SDP_MODE_SEL_SLAVE;
14198c2ecf20Sopenharmony_ci		rt5631->master = 0;
14208c2ecf20Sopenharmony_ci		break;
14218c2ecf20Sopenharmony_ci	default:
14228c2ecf20Sopenharmony_ci		return -EINVAL;
14238c2ecf20Sopenharmony_ci	}
14248c2ecf20Sopenharmony_ci
14258c2ecf20Sopenharmony_ci	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
14268c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_I2S:
14278c2ecf20Sopenharmony_ci		break;
14288c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_LEFT_J:
14298c2ecf20Sopenharmony_ci		iface |= RT5631_SDP_I2S_DF_LEFT;
14308c2ecf20Sopenharmony_ci		break;
14318c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_DSP_A:
14328c2ecf20Sopenharmony_ci		iface |= RT5631_SDP_I2S_DF_PCM_A;
14338c2ecf20Sopenharmony_ci		break;
14348c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_DSP_B:
14358c2ecf20Sopenharmony_ci		iface  |= RT5631_SDP_I2S_DF_PCM_B;
14368c2ecf20Sopenharmony_ci		break;
14378c2ecf20Sopenharmony_ci	default:
14388c2ecf20Sopenharmony_ci		return -EINVAL;
14398c2ecf20Sopenharmony_ci	}
14408c2ecf20Sopenharmony_ci
14418c2ecf20Sopenharmony_ci	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
14428c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_NB_NF:
14438c2ecf20Sopenharmony_ci		break;
14448c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_IB_NF:
14458c2ecf20Sopenharmony_ci		iface |= RT5631_SDP_I2S_BCLK_POL_CTRL;
14468c2ecf20Sopenharmony_ci		break;
14478c2ecf20Sopenharmony_ci	default:
14488c2ecf20Sopenharmony_ci		return -EINVAL;
14498c2ecf20Sopenharmony_ci	}
14508c2ecf20Sopenharmony_ci
14518c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_SDP_CTRL, iface);
14528c2ecf20Sopenharmony_ci
14538c2ecf20Sopenharmony_ci	return 0;
14548c2ecf20Sopenharmony_ci}
14558c2ecf20Sopenharmony_ci
14568c2ecf20Sopenharmony_cistatic int rt5631_hifi_codec_set_dai_sysclk(struct snd_soc_dai *codec_dai,
14578c2ecf20Sopenharmony_ci				int clk_id, unsigned int freq, int dir)
14588c2ecf20Sopenharmony_ci{
14598c2ecf20Sopenharmony_ci	struct snd_soc_component *component = codec_dai->component;
14608c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
14618c2ecf20Sopenharmony_ci
14628c2ecf20Sopenharmony_ci	dev_dbg(component->dev, "enter %s, syclk=%d\n", __func__, freq);
14638c2ecf20Sopenharmony_ci
14648c2ecf20Sopenharmony_ci	if ((freq >= (256 * 8000)) && (freq <= (512 * 96000))) {
14658c2ecf20Sopenharmony_ci		rt5631->sysclk = freq;
14668c2ecf20Sopenharmony_ci		return 0;
14678c2ecf20Sopenharmony_ci	}
14688c2ecf20Sopenharmony_ci
14698c2ecf20Sopenharmony_ci	return -EINVAL;
14708c2ecf20Sopenharmony_ci}
14718c2ecf20Sopenharmony_ci
14728c2ecf20Sopenharmony_cistatic int rt5631_codec_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
14738c2ecf20Sopenharmony_ci		int source, unsigned int freq_in, unsigned int freq_out)
14748c2ecf20Sopenharmony_ci{
14758c2ecf20Sopenharmony_ci	struct snd_soc_component *component = codec_dai->component;
14768c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
14778c2ecf20Sopenharmony_ci	int i, ret = -EINVAL;
14788c2ecf20Sopenharmony_ci
14798c2ecf20Sopenharmony_ci	dev_dbg(component->dev, "enter %s\n", __func__);
14808c2ecf20Sopenharmony_ci
14818c2ecf20Sopenharmony_ci	if (!freq_in || !freq_out) {
14828c2ecf20Sopenharmony_ci		dev_dbg(component->dev, "PLL disabled\n");
14838c2ecf20Sopenharmony_ci
14848c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_GLOBAL_CLK_CTRL,
14858c2ecf20Sopenharmony_ci			RT5631_SYSCLK_SOUR_SEL_MASK,
14868c2ecf20Sopenharmony_ci			RT5631_SYSCLK_SOUR_SEL_MCLK);
14878c2ecf20Sopenharmony_ci
14888c2ecf20Sopenharmony_ci		return 0;
14898c2ecf20Sopenharmony_ci	}
14908c2ecf20Sopenharmony_ci
14918c2ecf20Sopenharmony_ci	if (rt5631->master) {
14928c2ecf20Sopenharmony_ci		for (i = 0; i < ARRAY_SIZE(codec_master_pll_div); i++)
14938c2ecf20Sopenharmony_ci			if (freq_in == codec_master_pll_div[i].pll_in &&
14948c2ecf20Sopenharmony_ci			freq_out == codec_master_pll_div[i].pll_out) {
14958c2ecf20Sopenharmony_ci				dev_info(component->dev,
14968c2ecf20Sopenharmony_ci					"change PLL in master mode\n");
14978c2ecf20Sopenharmony_ci				snd_soc_component_write(component, RT5631_PLL_CTRL,
14988c2ecf20Sopenharmony_ci					codec_master_pll_div[i].reg_val);
14998c2ecf20Sopenharmony_ci				schedule_timeout_uninterruptible(
15008c2ecf20Sopenharmony_ci					msecs_to_jiffies(20));
15018c2ecf20Sopenharmony_ci				snd_soc_component_update_bits(component,
15028c2ecf20Sopenharmony_ci					RT5631_GLOBAL_CLK_CTRL,
15038c2ecf20Sopenharmony_ci					RT5631_SYSCLK_SOUR_SEL_MASK |
15048c2ecf20Sopenharmony_ci					RT5631_PLLCLK_SOUR_SEL_MASK,
15058c2ecf20Sopenharmony_ci					RT5631_SYSCLK_SOUR_SEL_PLL |
15068c2ecf20Sopenharmony_ci					RT5631_PLLCLK_SOUR_SEL_MCLK);
15078c2ecf20Sopenharmony_ci				ret = 0;
15088c2ecf20Sopenharmony_ci				break;
15098c2ecf20Sopenharmony_ci			}
15108c2ecf20Sopenharmony_ci	} else {
15118c2ecf20Sopenharmony_ci		for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++)
15128c2ecf20Sopenharmony_ci			if (freq_in == codec_slave_pll_div[i].pll_in &&
15138c2ecf20Sopenharmony_ci			freq_out == codec_slave_pll_div[i].pll_out) {
15148c2ecf20Sopenharmony_ci				dev_info(component->dev,
15158c2ecf20Sopenharmony_ci					"change PLL in slave mode\n");
15168c2ecf20Sopenharmony_ci				snd_soc_component_write(component, RT5631_PLL_CTRL,
15178c2ecf20Sopenharmony_ci					codec_slave_pll_div[i].reg_val);
15188c2ecf20Sopenharmony_ci				schedule_timeout_uninterruptible(
15198c2ecf20Sopenharmony_ci					msecs_to_jiffies(20));
15208c2ecf20Sopenharmony_ci				snd_soc_component_update_bits(component,
15218c2ecf20Sopenharmony_ci					RT5631_GLOBAL_CLK_CTRL,
15228c2ecf20Sopenharmony_ci					RT5631_SYSCLK_SOUR_SEL_MASK |
15238c2ecf20Sopenharmony_ci					RT5631_PLLCLK_SOUR_SEL_MASK,
15248c2ecf20Sopenharmony_ci					RT5631_SYSCLK_SOUR_SEL_PLL |
15258c2ecf20Sopenharmony_ci					RT5631_PLLCLK_SOUR_SEL_BCLK);
15268c2ecf20Sopenharmony_ci				ret = 0;
15278c2ecf20Sopenharmony_ci				break;
15288c2ecf20Sopenharmony_ci			}
15298c2ecf20Sopenharmony_ci	}
15308c2ecf20Sopenharmony_ci
15318c2ecf20Sopenharmony_ci	return ret;
15328c2ecf20Sopenharmony_ci}
15338c2ecf20Sopenharmony_ci
15348c2ecf20Sopenharmony_cistatic int rt5631_set_bias_level(struct snd_soc_component *component,
15358c2ecf20Sopenharmony_ci			enum snd_soc_bias_level level)
15368c2ecf20Sopenharmony_ci{
15378c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
15388c2ecf20Sopenharmony_ci
15398c2ecf20Sopenharmony_ci	switch (level) {
15408c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_ON:
15418c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_PREPARE:
15428c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD2,
15438c2ecf20Sopenharmony_ci			RT5631_PWR_MICBIAS1_VOL | RT5631_PWR_MICBIAS2_VOL,
15448c2ecf20Sopenharmony_ci			RT5631_PWR_MICBIAS1_VOL | RT5631_PWR_MICBIAS2_VOL);
15458c2ecf20Sopenharmony_ci		break;
15468c2ecf20Sopenharmony_ci
15478c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_STANDBY:
15488c2ecf20Sopenharmony_ci		if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
15498c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
15508c2ecf20Sopenharmony_ci				RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS,
15518c2ecf20Sopenharmony_ci				RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS);
15528c2ecf20Sopenharmony_ci			msleep(80);
15538c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
15548c2ecf20Sopenharmony_ci				RT5631_PWR_FAST_VREF_CTRL,
15558c2ecf20Sopenharmony_ci				RT5631_PWR_FAST_VREF_CTRL);
15568c2ecf20Sopenharmony_ci			regcache_cache_only(rt5631->regmap, false);
15578c2ecf20Sopenharmony_ci			regcache_sync(rt5631->regmap);
15588c2ecf20Sopenharmony_ci		}
15598c2ecf20Sopenharmony_ci		break;
15608c2ecf20Sopenharmony_ci
15618c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_OFF:
15628c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_PWR_MANAG_ADD1, 0x0000);
15638c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_PWR_MANAG_ADD2, 0x0000);
15648c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_PWR_MANAG_ADD3, 0x0000);
15658c2ecf20Sopenharmony_ci		snd_soc_component_write(component, RT5631_PWR_MANAG_ADD4, 0x0000);
15668c2ecf20Sopenharmony_ci		break;
15678c2ecf20Sopenharmony_ci
15688c2ecf20Sopenharmony_ci	default:
15698c2ecf20Sopenharmony_ci		break;
15708c2ecf20Sopenharmony_ci	}
15718c2ecf20Sopenharmony_ci
15728c2ecf20Sopenharmony_ci	return 0;
15738c2ecf20Sopenharmony_ci}
15748c2ecf20Sopenharmony_ci
15758c2ecf20Sopenharmony_cistatic int rt5631_probe(struct snd_soc_component *component)
15768c2ecf20Sopenharmony_ci{
15778c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
15788c2ecf20Sopenharmony_ci	unsigned int val;
15798c2ecf20Sopenharmony_ci
15808c2ecf20Sopenharmony_ci	val = rt5631_read_index(component, RT5631_ADDA_MIXER_INTL_REG3);
15818c2ecf20Sopenharmony_ci	if (val & 0x0002)
15828c2ecf20Sopenharmony_ci		rt5631->codec_version = 1;
15838c2ecf20Sopenharmony_ci	else
15848c2ecf20Sopenharmony_ci		rt5631->codec_version = 0;
15858c2ecf20Sopenharmony_ci
15868c2ecf20Sopenharmony_ci	rt5631_reset(component);
15878c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
15888c2ecf20Sopenharmony_ci		RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS,
15898c2ecf20Sopenharmony_ci		RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS);
15908c2ecf20Sopenharmony_ci	msleep(80);
15918c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
15928c2ecf20Sopenharmony_ci		RT5631_PWR_FAST_VREF_CTRL, RT5631_PWR_FAST_VREF_CTRL);
15938c2ecf20Sopenharmony_ci	/* enable HP zero cross */
15948c2ecf20Sopenharmony_ci	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, 0x0f18);
15958c2ecf20Sopenharmony_ci	/* power off ClassD auto Recovery */
15968c2ecf20Sopenharmony_ci	if (rt5631->codec_version)
15978c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_INT_ST_IRQ_CTRL_2,
15988c2ecf20Sopenharmony_ci					0x2000, 0x2000);
15998c2ecf20Sopenharmony_ci	else
16008c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_INT_ST_IRQ_CTRL_2,
16018c2ecf20Sopenharmony_ci					0x2000, 0);
16028c2ecf20Sopenharmony_ci	/* DMIC */
16038c2ecf20Sopenharmony_ci	if (rt5631->dmic_used_flag) {
16048c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_GPIO_CTRL,
16058c2ecf20Sopenharmony_ci			RT5631_GPIO_PIN_FUN_SEL_MASK |
16068c2ecf20Sopenharmony_ci			RT5631_GPIO_DMIC_FUN_SEL_MASK,
16078c2ecf20Sopenharmony_ci			RT5631_GPIO_PIN_FUN_SEL_GPIO_DIMC |
16088c2ecf20Sopenharmony_ci			RT5631_GPIO_DMIC_FUN_SEL_DIMC);
16098c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, RT5631_DIG_MIC_CTRL,
16108c2ecf20Sopenharmony_ci			RT5631_DMIC_L_CH_LATCH_MASK |
16118c2ecf20Sopenharmony_ci			RT5631_DMIC_R_CH_LATCH_MASK,
16128c2ecf20Sopenharmony_ci			RT5631_DMIC_L_CH_LATCH_FALLING |
16138c2ecf20Sopenharmony_ci			RT5631_DMIC_R_CH_LATCH_RISING);
16148c2ecf20Sopenharmony_ci	}
16158c2ecf20Sopenharmony_ci
16168c2ecf20Sopenharmony_ci	snd_soc_component_init_bias_level(component, SND_SOC_BIAS_STANDBY);
16178c2ecf20Sopenharmony_ci
16188c2ecf20Sopenharmony_ci	return 0;
16198c2ecf20Sopenharmony_ci}
16208c2ecf20Sopenharmony_ci
16218c2ecf20Sopenharmony_ci#define RT5631_STEREO_RATES SNDRV_PCM_RATE_8000_96000
16228c2ecf20Sopenharmony_ci#define RT5631_FORMAT	(SNDRV_PCM_FMTBIT_S16_LE | \
16238c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_S20_3LE | \
16248c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_S24_LE | \
16258c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_S8)
16268c2ecf20Sopenharmony_ci
16278c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops rt5631_ops = {
16288c2ecf20Sopenharmony_ci	.hw_params = rt5631_hifi_pcm_params,
16298c2ecf20Sopenharmony_ci	.set_fmt = rt5631_hifi_codec_set_dai_fmt,
16308c2ecf20Sopenharmony_ci	.set_sysclk = rt5631_hifi_codec_set_dai_sysclk,
16318c2ecf20Sopenharmony_ci	.set_pll = rt5631_codec_set_dai_pll,
16328c2ecf20Sopenharmony_ci};
16338c2ecf20Sopenharmony_ci
16348c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver rt5631_dai[] = {
16358c2ecf20Sopenharmony_ci	{
16368c2ecf20Sopenharmony_ci		.name = "rt5631-hifi",
16378c2ecf20Sopenharmony_ci		.id = 1,
16388c2ecf20Sopenharmony_ci		.playback = {
16398c2ecf20Sopenharmony_ci			.stream_name = "HIFI Playback",
16408c2ecf20Sopenharmony_ci			.channels_min = 1,
16418c2ecf20Sopenharmony_ci			.channels_max = 2,
16428c2ecf20Sopenharmony_ci			.rates = RT5631_STEREO_RATES,
16438c2ecf20Sopenharmony_ci			.formats = RT5631_FORMAT,
16448c2ecf20Sopenharmony_ci		},
16458c2ecf20Sopenharmony_ci		.capture = {
16468c2ecf20Sopenharmony_ci			.stream_name = "HIFI Capture",
16478c2ecf20Sopenharmony_ci			.channels_min = 1,
16488c2ecf20Sopenharmony_ci			.channels_max = 2,
16498c2ecf20Sopenharmony_ci			.rates = RT5631_STEREO_RATES,
16508c2ecf20Sopenharmony_ci			.formats = RT5631_FORMAT,
16518c2ecf20Sopenharmony_ci		},
16528c2ecf20Sopenharmony_ci		.ops = &rt5631_ops,
16538c2ecf20Sopenharmony_ci	},
16548c2ecf20Sopenharmony_ci};
16558c2ecf20Sopenharmony_ci
16568c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver soc_component_dev_rt5631 = {
16578c2ecf20Sopenharmony_ci	.probe			= rt5631_probe,
16588c2ecf20Sopenharmony_ci	.set_bias_level		= rt5631_set_bias_level,
16598c2ecf20Sopenharmony_ci	.controls		= rt5631_snd_controls,
16608c2ecf20Sopenharmony_ci	.num_controls		= ARRAY_SIZE(rt5631_snd_controls),
16618c2ecf20Sopenharmony_ci	.dapm_widgets		= rt5631_dapm_widgets,
16628c2ecf20Sopenharmony_ci	.num_dapm_widgets	= ARRAY_SIZE(rt5631_dapm_widgets),
16638c2ecf20Sopenharmony_ci	.dapm_routes		= rt5631_dapm_routes,
16648c2ecf20Sopenharmony_ci	.num_dapm_routes	= ARRAY_SIZE(rt5631_dapm_routes),
16658c2ecf20Sopenharmony_ci	.suspend_bias_off	= 1,
16668c2ecf20Sopenharmony_ci	.idle_bias_on		= 1,
16678c2ecf20Sopenharmony_ci	.use_pmdown_time	= 1,
16688c2ecf20Sopenharmony_ci	.endianness		= 1,
16698c2ecf20Sopenharmony_ci	.non_legacy_dai_naming	= 1,
16708c2ecf20Sopenharmony_ci};
16718c2ecf20Sopenharmony_ci
16728c2ecf20Sopenharmony_cistatic const struct i2c_device_id rt5631_i2c_id[] = {
16738c2ecf20Sopenharmony_ci	{ "rt5631", 0 },
16748c2ecf20Sopenharmony_ci	{ "alc5631", 0 },
16758c2ecf20Sopenharmony_ci	{ }
16768c2ecf20Sopenharmony_ci};
16778c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, rt5631_i2c_id);
16788c2ecf20Sopenharmony_ci
16798c2ecf20Sopenharmony_ci#ifdef CONFIG_OF
16808c2ecf20Sopenharmony_cistatic const struct of_device_id rt5631_i2c_dt_ids[] = {
16818c2ecf20Sopenharmony_ci	{ .compatible = "realtek,rt5631"},
16828c2ecf20Sopenharmony_ci	{ .compatible = "realtek,alc5631"},
16838c2ecf20Sopenharmony_ci	{ }
16848c2ecf20Sopenharmony_ci};
16858c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, rt5631_i2c_dt_ids);
16868c2ecf20Sopenharmony_ci#endif
16878c2ecf20Sopenharmony_ci
16888c2ecf20Sopenharmony_cistatic const struct regmap_config rt5631_regmap_config = {
16898c2ecf20Sopenharmony_ci	.reg_bits = 8,
16908c2ecf20Sopenharmony_ci	.val_bits = 16,
16918c2ecf20Sopenharmony_ci
16928c2ecf20Sopenharmony_ci	.readable_reg = rt5631_readable_register,
16938c2ecf20Sopenharmony_ci	.volatile_reg = rt5631_volatile_register,
16948c2ecf20Sopenharmony_ci	.max_register = RT5631_VENDOR_ID2,
16958c2ecf20Sopenharmony_ci	.reg_defaults = rt5631_reg,
16968c2ecf20Sopenharmony_ci	.num_reg_defaults = ARRAY_SIZE(rt5631_reg),
16978c2ecf20Sopenharmony_ci	.cache_type = REGCACHE_RBTREE,
16988c2ecf20Sopenharmony_ci	.use_single_read = true,
16998c2ecf20Sopenharmony_ci	.use_single_write = true,
17008c2ecf20Sopenharmony_ci};
17018c2ecf20Sopenharmony_ci
17028c2ecf20Sopenharmony_cistatic int rt5631_i2c_probe(struct i2c_client *i2c,
17038c2ecf20Sopenharmony_ci		    const struct i2c_device_id *id)
17048c2ecf20Sopenharmony_ci{
17058c2ecf20Sopenharmony_ci	struct rt5631_priv *rt5631;
17068c2ecf20Sopenharmony_ci	int ret;
17078c2ecf20Sopenharmony_ci
17088c2ecf20Sopenharmony_ci	rt5631 = devm_kzalloc(&i2c->dev, sizeof(struct rt5631_priv),
17098c2ecf20Sopenharmony_ci			      GFP_KERNEL);
17108c2ecf20Sopenharmony_ci	if (NULL == rt5631)
17118c2ecf20Sopenharmony_ci		return -ENOMEM;
17128c2ecf20Sopenharmony_ci
17138c2ecf20Sopenharmony_ci	i2c_set_clientdata(i2c, rt5631);
17148c2ecf20Sopenharmony_ci
17158c2ecf20Sopenharmony_ci	rt5631->regmap = devm_regmap_init_i2c(i2c, &rt5631_regmap_config);
17168c2ecf20Sopenharmony_ci	if (IS_ERR(rt5631->regmap))
17178c2ecf20Sopenharmony_ci		return PTR_ERR(rt5631->regmap);
17188c2ecf20Sopenharmony_ci
17198c2ecf20Sopenharmony_ci	ret = devm_snd_soc_register_component(&i2c->dev,
17208c2ecf20Sopenharmony_ci			&soc_component_dev_rt5631,
17218c2ecf20Sopenharmony_ci			rt5631_dai, ARRAY_SIZE(rt5631_dai));
17228c2ecf20Sopenharmony_ci	return ret;
17238c2ecf20Sopenharmony_ci}
17248c2ecf20Sopenharmony_ci
17258c2ecf20Sopenharmony_cistatic int rt5631_i2c_remove(struct i2c_client *client)
17268c2ecf20Sopenharmony_ci{
17278c2ecf20Sopenharmony_ci	return 0;
17288c2ecf20Sopenharmony_ci}
17298c2ecf20Sopenharmony_ci
17308c2ecf20Sopenharmony_cistatic struct i2c_driver rt5631_i2c_driver = {
17318c2ecf20Sopenharmony_ci	.driver = {
17328c2ecf20Sopenharmony_ci		.name = "rt5631",
17338c2ecf20Sopenharmony_ci		.of_match_table = of_match_ptr(rt5631_i2c_dt_ids),
17348c2ecf20Sopenharmony_ci	},
17358c2ecf20Sopenharmony_ci	.probe = rt5631_i2c_probe,
17368c2ecf20Sopenharmony_ci	.remove   = rt5631_i2c_remove,
17378c2ecf20Sopenharmony_ci	.id_table = rt5631_i2c_id,
17388c2ecf20Sopenharmony_ci};
17398c2ecf20Sopenharmony_ci
17408c2ecf20Sopenharmony_cimodule_i2c_driver(rt5631_i2c_driver);
17418c2ecf20Sopenharmony_ci
17428c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ASoC RT5631 driver");
17438c2ecf20Sopenharmony_ciMODULE_AUTHOR("flove <flove@realtek.com>");
17448c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
1745