xref: /openbmc/linux/sound/soc/codecs/rt5631.c (revision 2612e3bbc0386368a850140a6c9b990cd496a5ec)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2d8085222Sjohnnyhsu@realtek.com /*
3d8085222Sjohnnyhsu@realtek.com  * rt5631.c  --  RT5631 ALSA Soc Audio driver
4d8085222Sjohnnyhsu@realtek.com  *
5d8085222Sjohnnyhsu@realtek.com  * Copyright 2011 Realtek Microelectronics
6d8085222Sjohnnyhsu@realtek.com  *
7d8085222Sjohnnyhsu@realtek.com  * Author: flove <flove@realtek.com>
8d8085222Sjohnnyhsu@realtek.com  *
9d8085222Sjohnnyhsu@realtek.com  * Based on WM8753.c
10d8085222Sjohnnyhsu@realtek.com  */
11d8085222Sjohnnyhsu@realtek.com #include <linux/module.h>
12d8085222Sjohnnyhsu@realtek.com #include <linux/moduleparam.h>
13d8085222Sjohnnyhsu@realtek.com #include <linux/init.h>
14d8085222Sjohnnyhsu@realtek.com #include <linux/delay.h>
15d8085222Sjohnnyhsu@realtek.com #include <linux/pm.h>
16d8085222Sjohnnyhsu@realtek.com #include <linux/i2c.h>
1701476801SMark Brown #include <linux/regmap.h>
18d8085222Sjohnnyhsu@realtek.com #include <sound/core.h>
19d8085222Sjohnnyhsu@realtek.com #include <sound/pcm.h>
20d8085222Sjohnnyhsu@realtek.com #include <sound/pcm_params.h>
21d8085222Sjohnnyhsu@realtek.com #include <sound/soc.h>
22d8085222Sjohnnyhsu@realtek.com #include <sound/soc-dapm.h>
23d8085222Sjohnnyhsu@realtek.com #include <sound/initval.h>
24d8085222Sjohnnyhsu@realtek.com #include <sound/tlv.h>
25d8085222Sjohnnyhsu@realtek.com 
26d8085222Sjohnnyhsu@realtek.com #include "rt5631.h"
27d8085222Sjohnnyhsu@realtek.com 
28d8085222Sjohnnyhsu@realtek.com struct rt5631_priv {
2901476801SMark Brown 	struct regmap *regmap;
30d8085222Sjohnnyhsu@realtek.com 	int codec_version;
31d8085222Sjohnnyhsu@realtek.com 	int master;
32d8085222Sjohnnyhsu@realtek.com 	int sysclk;
33d8085222Sjohnnyhsu@realtek.com 	int rx_rate;
34d8085222Sjohnnyhsu@realtek.com 	int bclk_rate;
35d8085222Sjohnnyhsu@realtek.com 	int dmic_used_flag;
36d8085222Sjohnnyhsu@realtek.com };
37d8085222Sjohnnyhsu@realtek.com 
3801476801SMark Brown static const struct reg_default rt5631_reg[] = {
3901476801SMark Brown 	{ RT5631_SPK_OUT_VOL, 0x8888 },
4001476801SMark Brown 	{ RT5631_HP_OUT_VOL, 0x8080 },
4101476801SMark Brown 	{ RT5631_MONO_AXO_1_2_VOL, 0xa080 },
4201476801SMark Brown 	{ RT5631_AUX_IN_VOL, 0x0808 },
4301476801SMark Brown 	{ RT5631_ADC_REC_MIXER, 0xf0f0 },
4401476801SMark Brown 	{ RT5631_VDAC_DIG_VOL, 0x0010 },
4501476801SMark Brown 	{ RT5631_OUTMIXER_L_CTRL, 0xffc0 },
4601476801SMark Brown 	{ RT5631_OUTMIXER_R_CTRL, 0xffc0 },
4701476801SMark Brown 	{ RT5631_AXO1MIXER_CTRL, 0x88c0 },
4801476801SMark Brown 	{ RT5631_AXO2MIXER_CTRL, 0x88c0 },
4901476801SMark Brown 	{ RT5631_DIG_MIC_CTRL, 0x3000 },
5001476801SMark Brown 	{ RT5631_MONO_INPUT_VOL, 0x8808 },
5101476801SMark Brown 	{ RT5631_SPK_MIXER_CTRL, 0xf8f8 },
5201476801SMark Brown 	{ RT5631_SPK_MONO_OUT_CTRL, 0xfc00 },
5301476801SMark Brown 	{ RT5631_SPK_MONO_HP_OUT_CTRL, 0x4440 },
5401476801SMark Brown 	{ RT5631_SDP_CTRL, 0x8000 },
5501476801SMark Brown 	{ RT5631_MONO_SDP_CTRL, 0x8000 },
5601476801SMark Brown 	{ RT5631_STEREO_AD_DA_CLK_CTRL, 0x2010 },
5701476801SMark Brown 	{ RT5631_GEN_PUR_CTRL_REG, 0x0e00 },
5801476801SMark Brown 	{ RT5631_INT_ST_IRQ_CTRL_2, 0x071a },
5901476801SMark Brown 	{ RT5631_MISC_CTRL, 0x2040 },
6001476801SMark Brown 	{ RT5631_DEPOP_FUN_CTRL_2, 0x8000 },
6101476801SMark Brown 	{ RT5631_SOFT_VOL_CTRL, 0x07e0 },
6201476801SMark Brown 	{ RT5631_ALC_CTRL_1, 0x0206 },
6301476801SMark Brown 	{ RT5631_ALC_CTRL_3, 0x2000 },
6401476801SMark Brown 	{ RT5631_PSEUDO_SPATL_CTRL, 0x0553 },
65d8085222Sjohnnyhsu@realtek.com };
66d8085222Sjohnnyhsu@realtek.com 
67762a3d43SPierre-Louis Bossart /*
68d8085222Sjohnnyhsu@realtek.com  * rt5631_write_index - write index register of 2nd layer
69d8085222Sjohnnyhsu@realtek.com  */
rt5631_write_index(struct snd_soc_component * component,unsigned int reg,unsigned int value)7046295e5eSKuninori Morimoto static void rt5631_write_index(struct snd_soc_component *component,
71d8085222Sjohnnyhsu@realtek.com 		unsigned int reg, unsigned int value)
72d8085222Sjohnnyhsu@realtek.com {
7346295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INDEX_ADD, reg);
7446295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INDEX_DATA, value);
75d8085222Sjohnnyhsu@realtek.com }
76d8085222Sjohnnyhsu@realtek.com 
77762a3d43SPierre-Louis Bossart /*
78d8085222Sjohnnyhsu@realtek.com  * rt5631_read_index - read index register of 2nd layer
79d8085222Sjohnnyhsu@realtek.com  */
rt5631_read_index(struct snd_soc_component * component,unsigned int reg)8046295e5eSKuninori Morimoto static unsigned int rt5631_read_index(struct snd_soc_component *component,
81d8085222Sjohnnyhsu@realtek.com 				unsigned int reg)
82d8085222Sjohnnyhsu@realtek.com {
83d8085222Sjohnnyhsu@realtek.com 	unsigned int value;
84d8085222Sjohnnyhsu@realtek.com 
8546295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INDEX_ADD, reg);
86467a2553SKuninori Morimoto 	value = snd_soc_component_read(component, RT5631_INDEX_DATA);
87d8085222Sjohnnyhsu@realtek.com 
88d8085222Sjohnnyhsu@realtek.com 	return value;
89d8085222Sjohnnyhsu@realtek.com }
90d8085222Sjohnnyhsu@realtek.com 
rt5631_reset(struct snd_soc_component * component)9146295e5eSKuninori Morimoto static int rt5631_reset(struct snd_soc_component *component)
92d8085222Sjohnnyhsu@realtek.com {
9346295e5eSKuninori Morimoto 	return snd_soc_component_write(component, RT5631_RESET, 0);
94d8085222Sjohnnyhsu@realtek.com }
95d8085222Sjohnnyhsu@realtek.com 
rt5631_volatile_register(struct device * dev,unsigned int reg)9601476801SMark Brown static bool rt5631_volatile_register(struct device *dev, unsigned int reg)
97d8085222Sjohnnyhsu@realtek.com {
98d8085222Sjohnnyhsu@realtek.com 	switch (reg) {
99d8085222Sjohnnyhsu@realtek.com 	case RT5631_RESET:
100d8085222Sjohnnyhsu@realtek.com 	case RT5631_INT_ST_IRQ_CTRL_2:
101d8085222Sjohnnyhsu@realtek.com 	case RT5631_INDEX_ADD:
102d8085222Sjohnnyhsu@realtek.com 	case RT5631_INDEX_DATA:
103d8085222Sjohnnyhsu@realtek.com 	case RT5631_EQ_CTRL:
104508e8641SGustavo A. R. Silva 		return true;
105d8085222Sjohnnyhsu@realtek.com 	default:
106508e8641SGustavo A. R. Silva 		return false;
107d8085222Sjohnnyhsu@realtek.com 	}
108d8085222Sjohnnyhsu@realtek.com }
109d8085222Sjohnnyhsu@realtek.com 
rt5631_readable_register(struct device * dev,unsigned int reg)11001476801SMark Brown static bool rt5631_readable_register(struct device *dev, unsigned int reg)
111d8085222Sjohnnyhsu@realtek.com {
112d8085222Sjohnnyhsu@realtek.com 	switch (reg) {
113d8085222Sjohnnyhsu@realtek.com 	case RT5631_RESET:
114d8085222Sjohnnyhsu@realtek.com 	case RT5631_SPK_OUT_VOL:
115d8085222Sjohnnyhsu@realtek.com 	case RT5631_HP_OUT_VOL:
116d8085222Sjohnnyhsu@realtek.com 	case RT5631_MONO_AXO_1_2_VOL:
117d8085222Sjohnnyhsu@realtek.com 	case RT5631_AUX_IN_VOL:
118d8085222Sjohnnyhsu@realtek.com 	case RT5631_STEREO_DAC_VOL_1:
119d8085222Sjohnnyhsu@realtek.com 	case RT5631_MIC_CTRL_1:
120d8085222Sjohnnyhsu@realtek.com 	case RT5631_STEREO_DAC_VOL_2:
121d8085222Sjohnnyhsu@realtek.com 	case RT5631_ADC_CTRL_1:
122d8085222Sjohnnyhsu@realtek.com 	case RT5631_ADC_REC_MIXER:
123d8085222Sjohnnyhsu@realtek.com 	case RT5631_ADC_CTRL_2:
124d8085222Sjohnnyhsu@realtek.com 	case RT5631_VDAC_DIG_VOL:
125d8085222Sjohnnyhsu@realtek.com 	case RT5631_OUTMIXER_L_CTRL:
126d8085222Sjohnnyhsu@realtek.com 	case RT5631_OUTMIXER_R_CTRL:
127d8085222Sjohnnyhsu@realtek.com 	case RT5631_AXO1MIXER_CTRL:
128d8085222Sjohnnyhsu@realtek.com 	case RT5631_AXO2MIXER_CTRL:
129d8085222Sjohnnyhsu@realtek.com 	case RT5631_MIC_CTRL_2:
130d8085222Sjohnnyhsu@realtek.com 	case RT5631_DIG_MIC_CTRL:
131d8085222Sjohnnyhsu@realtek.com 	case RT5631_MONO_INPUT_VOL:
132d8085222Sjohnnyhsu@realtek.com 	case RT5631_SPK_MIXER_CTRL:
133d8085222Sjohnnyhsu@realtek.com 	case RT5631_SPK_MONO_OUT_CTRL:
134d8085222Sjohnnyhsu@realtek.com 	case RT5631_SPK_MONO_HP_OUT_CTRL:
135d8085222Sjohnnyhsu@realtek.com 	case RT5631_SDP_CTRL:
136d8085222Sjohnnyhsu@realtek.com 	case RT5631_MONO_SDP_CTRL:
137d8085222Sjohnnyhsu@realtek.com 	case RT5631_STEREO_AD_DA_CLK_CTRL:
138d8085222Sjohnnyhsu@realtek.com 	case RT5631_PWR_MANAG_ADD1:
139d8085222Sjohnnyhsu@realtek.com 	case RT5631_PWR_MANAG_ADD2:
140d8085222Sjohnnyhsu@realtek.com 	case RT5631_PWR_MANAG_ADD3:
141d8085222Sjohnnyhsu@realtek.com 	case RT5631_PWR_MANAG_ADD4:
142d8085222Sjohnnyhsu@realtek.com 	case RT5631_GEN_PUR_CTRL_REG:
143d8085222Sjohnnyhsu@realtek.com 	case RT5631_GLOBAL_CLK_CTRL:
144d8085222Sjohnnyhsu@realtek.com 	case RT5631_PLL_CTRL:
145d8085222Sjohnnyhsu@realtek.com 	case RT5631_INT_ST_IRQ_CTRL_1:
146d8085222Sjohnnyhsu@realtek.com 	case RT5631_INT_ST_IRQ_CTRL_2:
147d8085222Sjohnnyhsu@realtek.com 	case RT5631_GPIO_CTRL:
148d8085222Sjohnnyhsu@realtek.com 	case RT5631_MISC_CTRL:
149d8085222Sjohnnyhsu@realtek.com 	case RT5631_DEPOP_FUN_CTRL_1:
150d8085222Sjohnnyhsu@realtek.com 	case RT5631_DEPOP_FUN_CTRL_2:
151d8085222Sjohnnyhsu@realtek.com 	case RT5631_JACK_DET_CTRL:
152d8085222Sjohnnyhsu@realtek.com 	case RT5631_SOFT_VOL_CTRL:
153d8085222Sjohnnyhsu@realtek.com 	case RT5631_ALC_CTRL_1:
154d8085222Sjohnnyhsu@realtek.com 	case RT5631_ALC_CTRL_2:
155d8085222Sjohnnyhsu@realtek.com 	case RT5631_ALC_CTRL_3:
156d8085222Sjohnnyhsu@realtek.com 	case RT5631_PSEUDO_SPATL_CTRL:
157d8085222Sjohnnyhsu@realtek.com 	case RT5631_INDEX_ADD:
158d8085222Sjohnnyhsu@realtek.com 	case RT5631_INDEX_DATA:
159d8085222Sjohnnyhsu@realtek.com 	case RT5631_EQ_CTRL:
160d8085222Sjohnnyhsu@realtek.com 	case RT5631_VENDOR_ID:
161d8085222Sjohnnyhsu@realtek.com 	case RT5631_VENDOR_ID1:
162d8085222Sjohnnyhsu@realtek.com 	case RT5631_VENDOR_ID2:
163508e8641SGustavo A. R. Silva 		return true;
164d8085222Sjohnnyhsu@realtek.com 	default:
165508e8641SGustavo A. R. Silva 		return false;
166d8085222Sjohnnyhsu@realtek.com 	}
167d8085222Sjohnnyhsu@realtek.com }
168d8085222Sjohnnyhsu@realtek.com 
169d8085222Sjohnnyhsu@realtek.com static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
170d8085222Sjohnnyhsu@realtek.com static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -95625, 375, 0);
171d8085222Sjohnnyhsu@realtek.com static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
172d8085222Sjohnnyhsu@realtek.com /* {0, +20, +24, +30, +35, +40, +44, +50, +52}dB */
1737f708abeSLars-Peter Clausen static const DECLARE_TLV_DB_RANGE(mic_bst_tlv,
174d8085222Sjohnnyhsu@realtek.com 	0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
175d8085222Sjohnnyhsu@realtek.com 	1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
176d8085222Sjohnnyhsu@realtek.com 	2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
177d8085222Sjohnnyhsu@realtek.com 	3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
178d8085222Sjohnnyhsu@realtek.com 	6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
179d8085222Sjohnnyhsu@realtek.com 	7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
1807f708abeSLars-Peter Clausen 	8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0)
1817f708abeSLars-Peter Clausen );
182d8085222Sjohnnyhsu@realtek.com 
rt5631_dmic_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)183d8085222Sjohnnyhsu@realtek.com static int rt5631_dmic_get(struct snd_kcontrol *kcontrol,
184d8085222Sjohnnyhsu@realtek.com 		struct snd_ctl_elem_value *ucontrol)
185d8085222Sjohnnyhsu@realtek.com {
18646295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
18746295e5eSKuninori Morimoto 	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
188d8085222Sjohnnyhsu@realtek.com 
189d8085222Sjohnnyhsu@realtek.com 	ucontrol->value.integer.value[0] = rt5631->dmic_used_flag;
190d8085222Sjohnnyhsu@realtek.com 
191d8085222Sjohnnyhsu@realtek.com 	return 0;
192d8085222Sjohnnyhsu@realtek.com }
193d8085222Sjohnnyhsu@realtek.com 
rt5631_dmic_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)194d8085222Sjohnnyhsu@realtek.com static int rt5631_dmic_put(struct snd_kcontrol *kcontrol,
195d8085222Sjohnnyhsu@realtek.com 		struct snd_ctl_elem_value *ucontrol)
196d8085222Sjohnnyhsu@realtek.com {
19746295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
19846295e5eSKuninori Morimoto 	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
199d8085222Sjohnnyhsu@realtek.com 
200d8085222Sjohnnyhsu@realtek.com 	rt5631->dmic_used_flag = ucontrol->value.integer.value[0];
201d8085222Sjohnnyhsu@realtek.com 	return 0;
202d8085222Sjohnnyhsu@realtek.com }
203d8085222Sjohnnyhsu@realtek.com 
204d8085222Sjohnnyhsu@realtek.com /* MIC Input Type */
205d8085222Sjohnnyhsu@realtek.com static const char *rt5631_input_mode[] = {
206d8085222Sjohnnyhsu@realtek.com 	"Single ended", "Differential"};
207d8085222Sjohnnyhsu@realtek.com 
208f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_mic1_mode_enum, RT5631_MIC_CTRL_1,
209d8085222Sjohnnyhsu@realtek.com 			    RT5631_MIC1_DIFF_INPUT_SHIFT, rt5631_input_mode);
210d8085222Sjohnnyhsu@realtek.com 
211f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_mic2_mode_enum, RT5631_MIC_CTRL_1,
212d8085222Sjohnnyhsu@realtek.com 			    RT5631_MIC2_DIFF_INPUT_SHIFT, rt5631_input_mode);
213d8085222Sjohnnyhsu@realtek.com 
214d8085222Sjohnnyhsu@realtek.com /* MONO Input Type */
215f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_monoin_mode_enum, RT5631_MONO_INPUT_VOL,
216d8085222Sjohnnyhsu@realtek.com 			    RT5631_MONO_DIFF_INPUT_SHIFT, rt5631_input_mode);
217d8085222Sjohnnyhsu@realtek.com 
218d8085222Sjohnnyhsu@realtek.com /* SPK Ratio Gain Control */
219d8085222Sjohnnyhsu@realtek.com static const char *rt5631_spk_ratio[] = {"1.00x", "1.09x", "1.27x", "1.44x",
220d8085222Sjohnnyhsu@realtek.com 			"1.56x", "1.68x", "1.99x", "2.34x"};
221d8085222Sjohnnyhsu@realtek.com 
222f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_spk_ratio_enum, RT5631_GEN_PUR_CTRL_REG,
223d8085222Sjohnnyhsu@realtek.com 			    RT5631_SPK_AMP_RATIO_CTRL_SHIFT, rt5631_spk_ratio);
224d8085222Sjohnnyhsu@realtek.com 
225d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_snd_controls[] = {
226d8085222Sjohnnyhsu@realtek.com 	/* MIC */
227d8085222Sjohnnyhsu@realtek.com 	SOC_ENUM("MIC1 Mode Control",  rt5631_mic1_mode_enum),
228d77a7608SBard Liao 	SOC_SINGLE_TLV("MIC1 Boost Volume", RT5631_MIC_CTRL_2,
229d8085222Sjohnnyhsu@realtek.com 		RT5631_MIC1_BOOST_SHIFT, 8, 0, mic_bst_tlv),
230d8085222Sjohnnyhsu@realtek.com 	SOC_ENUM("MIC2 Mode Control", rt5631_mic2_mode_enum),
231d77a7608SBard Liao 	SOC_SINGLE_TLV("MIC2 Boost Volume", RT5631_MIC_CTRL_2,
232d8085222Sjohnnyhsu@realtek.com 		RT5631_MIC2_BOOST_SHIFT, 8, 0, mic_bst_tlv),
233d8085222Sjohnnyhsu@realtek.com 	/* MONO IN */
234d8085222Sjohnnyhsu@realtek.com 	SOC_ENUM("MONOIN Mode Control", rt5631_monoin_mode_enum),
235d8085222Sjohnnyhsu@realtek.com 	SOC_DOUBLE_TLV("MONOIN_RX Capture Volume", RT5631_MONO_INPUT_VOL,
236d8085222Sjohnnyhsu@realtek.com 			RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
237d8085222Sjohnnyhsu@realtek.com 			RT5631_VOL_MASK, 1, in_vol_tlv),
238d8085222Sjohnnyhsu@realtek.com 	/* AXI */
239d8085222Sjohnnyhsu@realtek.com 	SOC_DOUBLE_TLV("AXI Capture Volume", RT5631_AUX_IN_VOL,
240d8085222Sjohnnyhsu@realtek.com 			RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
241d8085222Sjohnnyhsu@realtek.com 			RT5631_VOL_MASK, 1, in_vol_tlv),
242d8085222Sjohnnyhsu@realtek.com 	/* DAC */
243d8085222Sjohnnyhsu@realtek.com 	SOC_DOUBLE_TLV("PCM Playback Volume", RT5631_STEREO_DAC_VOL_2,
244d8085222Sjohnnyhsu@realtek.com 			RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
245d8085222Sjohnnyhsu@realtek.com 			RT5631_DAC_VOL_MASK, 1, dac_vol_tlv),
246d8085222Sjohnnyhsu@realtek.com 	SOC_DOUBLE("PCM Playback Switch", RT5631_STEREO_DAC_VOL_1,
247d8085222Sjohnnyhsu@realtek.com 			RT5631_L_MUTE_SHIFT, RT5631_R_MUTE_SHIFT, 1, 1),
248d8085222Sjohnnyhsu@realtek.com 	/* AXO */
249d8085222Sjohnnyhsu@realtek.com 	SOC_SINGLE("AXO1 Playback Switch", RT5631_MONO_AXO_1_2_VOL,
250d8085222Sjohnnyhsu@realtek.com 				RT5631_L_MUTE_SHIFT, 1, 1),
251d8085222Sjohnnyhsu@realtek.com 	SOC_SINGLE("AXO2 Playback Switch", RT5631_MONO_AXO_1_2_VOL,
252d8085222Sjohnnyhsu@realtek.com 				RT5631_R_VOL_SHIFT, 1, 1),
253d8085222Sjohnnyhsu@realtek.com 	/* OUTVOL */
254d8085222Sjohnnyhsu@realtek.com 	SOC_DOUBLE("OUTVOL Channel Switch", RT5631_SPK_OUT_VOL,
255d8085222Sjohnnyhsu@realtek.com 		RT5631_L_EN_SHIFT, RT5631_R_EN_SHIFT, 1, 0),
256d8085222Sjohnnyhsu@realtek.com 
257d8085222Sjohnnyhsu@realtek.com 	/* SPK */
258d8085222Sjohnnyhsu@realtek.com 	SOC_DOUBLE("Speaker Playback Switch", RT5631_SPK_OUT_VOL,
259d8085222Sjohnnyhsu@realtek.com 		RT5631_L_MUTE_SHIFT, RT5631_R_MUTE_SHIFT, 1, 1),
260d8085222Sjohnnyhsu@realtek.com 	SOC_DOUBLE_TLV("Speaker Playback Volume", RT5631_SPK_OUT_VOL,
261d8085222Sjohnnyhsu@realtek.com 		RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT, 39, 1, out_vol_tlv),
262d8085222Sjohnnyhsu@realtek.com 	/* MONO OUT */
263d8085222Sjohnnyhsu@realtek.com 	SOC_SINGLE("MONO Playback Switch", RT5631_MONO_AXO_1_2_VOL,
264d8085222Sjohnnyhsu@realtek.com 				RT5631_MUTE_MONO_SHIFT, 1, 1),
265d8085222Sjohnnyhsu@realtek.com 	/* HP */
266d8085222Sjohnnyhsu@realtek.com 	SOC_DOUBLE("HP Playback Switch", RT5631_HP_OUT_VOL,
267d8085222Sjohnnyhsu@realtek.com 		RT5631_L_MUTE_SHIFT, RT5631_R_MUTE_SHIFT, 1, 1),
268d8085222Sjohnnyhsu@realtek.com 	SOC_DOUBLE_TLV("HP Playback Volume", RT5631_HP_OUT_VOL,
269d8085222Sjohnnyhsu@realtek.com 		RT5631_L_VOL_SHIFT, RT5631_R_VOL_SHIFT,
270d8085222Sjohnnyhsu@realtek.com 		RT5631_VOL_MASK, 1, out_vol_tlv),
271d8085222Sjohnnyhsu@realtek.com 	/* DMIC */
272d8085222Sjohnnyhsu@realtek.com 	SOC_SINGLE_EXT("DMIC Switch", 0, 0, 1, 0,
273d8085222Sjohnnyhsu@realtek.com 		rt5631_dmic_get, rt5631_dmic_put),
274d8085222Sjohnnyhsu@realtek.com 	SOC_DOUBLE("DMIC Capture Switch", RT5631_DIG_MIC_CTRL,
275d8085222Sjohnnyhsu@realtek.com 		RT5631_DMIC_L_CH_MUTE_SHIFT,
276d8085222Sjohnnyhsu@realtek.com 		RT5631_DMIC_R_CH_MUTE_SHIFT, 1, 1),
277d8085222Sjohnnyhsu@realtek.com 
278d8085222Sjohnnyhsu@realtek.com 	/* SPK Ratio Gain Control */
279d8085222Sjohnnyhsu@realtek.com 	SOC_ENUM("SPK Ratio Control", rt5631_spk_ratio_enum),
280d8085222Sjohnnyhsu@realtek.com };
281d8085222Sjohnnyhsu@realtek.com 
check_sysclk1_source(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)282d8085222Sjohnnyhsu@realtek.com static int check_sysclk1_source(struct snd_soc_dapm_widget *source,
283d8085222Sjohnnyhsu@realtek.com 			 struct snd_soc_dapm_widget *sink)
284d8085222Sjohnnyhsu@realtek.com {
28546295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
286d8085222Sjohnnyhsu@realtek.com 	unsigned int reg;
287d8085222Sjohnnyhsu@realtek.com 
288467a2553SKuninori Morimoto 	reg = snd_soc_component_read(component, RT5631_GLOBAL_CLK_CTRL);
289d8085222Sjohnnyhsu@realtek.com 	return reg & RT5631_SYSCLK_SOUR_SEL_PLL;
290d8085222Sjohnnyhsu@realtek.com }
291d8085222Sjohnnyhsu@realtek.com 
check_dmic_used(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)292d8085222Sjohnnyhsu@realtek.com static int check_dmic_used(struct snd_soc_dapm_widget *source,
293d8085222Sjohnnyhsu@realtek.com 			 struct snd_soc_dapm_widget *sink)
294d8085222Sjohnnyhsu@realtek.com {
29546295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
29646295e5eSKuninori Morimoto 	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
297d8085222Sjohnnyhsu@realtek.com 	return rt5631->dmic_used_flag;
298d8085222Sjohnnyhsu@realtek.com }
299d8085222Sjohnnyhsu@realtek.com 
check_dacl_to_outmixl(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)300d8085222Sjohnnyhsu@realtek.com static int check_dacl_to_outmixl(struct snd_soc_dapm_widget *source,
301d8085222Sjohnnyhsu@realtek.com 			 struct snd_soc_dapm_widget *sink)
302d8085222Sjohnnyhsu@realtek.com {
30346295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
304d8085222Sjohnnyhsu@realtek.com 	unsigned int reg;
305d8085222Sjohnnyhsu@realtek.com 
306467a2553SKuninori Morimoto 	reg = snd_soc_component_read(component, RT5631_OUTMIXER_L_CTRL);
307d8085222Sjohnnyhsu@realtek.com 	return !(reg & RT5631_M_DAC_L_TO_OUTMIXER_L);
308d8085222Sjohnnyhsu@realtek.com }
309d8085222Sjohnnyhsu@realtek.com 
check_dacr_to_outmixr(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)310d8085222Sjohnnyhsu@realtek.com static int check_dacr_to_outmixr(struct snd_soc_dapm_widget *source,
311d8085222Sjohnnyhsu@realtek.com 			 struct snd_soc_dapm_widget *sink)
312d8085222Sjohnnyhsu@realtek.com {
31346295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
314d8085222Sjohnnyhsu@realtek.com 	unsigned int reg;
315d8085222Sjohnnyhsu@realtek.com 
316467a2553SKuninori Morimoto 	reg = snd_soc_component_read(component, RT5631_OUTMIXER_R_CTRL);
317d8085222Sjohnnyhsu@realtek.com 	return !(reg & RT5631_M_DAC_R_TO_OUTMIXER_R);
318d8085222Sjohnnyhsu@realtek.com }
319d8085222Sjohnnyhsu@realtek.com 
check_dacl_to_spkmixl(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)320d8085222Sjohnnyhsu@realtek.com static int check_dacl_to_spkmixl(struct snd_soc_dapm_widget *source,
321d8085222Sjohnnyhsu@realtek.com 			 struct snd_soc_dapm_widget *sink)
322d8085222Sjohnnyhsu@realtek.com {
32346295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
324d8085222Sjohnnyhsu@realtek.com 	unsigned int reg;
325d8085222Sjohnnyhsu@realtek.com 
326467a2553SKuninori Morimoto 	reg = snd_soc_component_read(component, RT5631_SPK_MIXER_CTRL);
327d8085222Sjohnnyhsu@realtek.com 	return !(reg & RT5631_M_DAC_L_TO_SPKMIXER_L);
328d8085222Sjohnnyhsu@realtek.com }
329d8085222Sjohnnyhsu@realtek.com 
check_dacr_to_spkmixr(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)330d8085222Sjohnnyhsu@realtek.com static int check_dacr_to_spkmixr(struct snd_soc_dapm_widget *source,
331d8085222Sjohnnyhsu@realtek.com 			 struct snd_soc_dapm_widget *sink)
332d8085222Sjohnnyhsu@realtek.com {
33346295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
334d8085222Sjohnnyhsu@realtek.com 	unsigned int reg;
335d8085222Sjohnnyhsu@realtek.com 
336467a2553SKuninori Morimoto 	reg = snd_soc_component_read(component, RT5631_SPK_MIXER_CTRL);
337d8085222Sjohnnyhsu@realtek.com 	return !(reg & RT5631_M_DAC_R_TO_SPKMIXER_R);
338d8085222Sjohnnyhsu@realtek.com }
339d8085222Sjohnnyhsu@realtek.com 
check_adcl_select(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)340d8085222Sjohnnyhsu@realtek.com static int check_adcl_select(struct snd_soc_dapm_widget *source,
341d8085222Sjohnnyhsu@realtek.com 			 struct snd_soc_dapm_widget *sink)
342d8085222Sjohnnyhsu@realtek.com {
34346295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
344d8085222Sjohnnyhsu@realtek.com 	unsigned int reg;
345d8085222Sjohnnyhsu@realtek.com 
346467a2553SKuninori Morimoto 	reg = snd_soc_component_read(component, RT5631_ADC_REC_MIXER);
347d8085222Sjohnnyhsu@realtek.com 	return !(reg & RT5631_M_MIC1_TO_RECMIXER_L);
348d8085222Sjohnnyhsu@realtek.com }
349d8085222Sjohnnyhsu@realtek.com 
check_adcr_select(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)350d8085222Sjohnnyhsu@realtek.com static int check_adcr_select(struct snd_soc_dapm_widget *source,
351d8085222Sjohnnyhsu@realtek.com 			 struct snd_soc_dapm_widget *sink)
352d8085222Sjohnnyhsu@realtek.com {
35346295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
354d8085222Sjohnnyhsu@realtek.com 	unsigned int reg;
355d8085222Sjohnnyhsu@realtek.com 
356467a2553SKuninori Morimoto 	reg = snd_soc_component_read(component, RT5631_ADC_REC_MIXER);
357d8085222Sjohnnyhsu@realtek.com 	return !(reg & RT5631_M_MIC2_TO_RECMIXER_R);
358d8085222Sjohnnyhsu@realtek.com }
359d8085222Sjohnnyhsu@realtek.com 
360d8085222Sjohnnyhsu@realtek.com /**
361d8085222Sjohnnyhsu@realtek.com  * onebit_depop_power_stage - auto depop in power stage.
362762a3d43SPierre-Louis Bossart  * @component: ASoC component
363d8085222Sjohnnyhsu@realtek.com  * @enable: power on/off
364d8085222Sjohnnyhsu@realtek.com  *
365d8085222Sjohnnyhsu@realtek.com  * When power on/off headphone, the depop sequence is done by hardware.
366d8085222Sjohnnyhsu@realtek.com  */
onebit_depop_power_stage(struct snd_soc_component * component,int enable)36746295e5eSKuninori Morimoto static void onebit_depop_power_stage(struct snd_soc_component *component, int enable)
368d8085222Sjohnnyhsu@realtek.com {
369d8085222Sjohnnyhsu@realtek.com 	unsigned int soft_vol, hp_zc;
370d8085222Sjohnnyhsu@realtek.com 
371d8085222Sjohnnyhsu@realtek.com 	/* enable one-bit depop function */
37246295e5eSKuninori Morimoto 	snd_soc_component_update_bits(component, RT5631_DEPOP_FUN_CTRL_2,
373d8085222Sjohnnyhsu@realtek.com 				RT5631_EN_ONE_BIT_DEPOP, 0);
374d8085222Sjohnnyhsu@realtek.com 
375d8085222Sjohnnyhsu@realtek.com 	/* keep soft volume and zero crossing setting */
376467a2553SKuninori Morimoto 	soft_vol = snd_soc_component_read(component, RT5631_SOFT_VOL_CTRL);
37746295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, 0);
378467a2553SKuninori Morimoto 	hp_zc = snd_soc_component_read(component, RT5631_INT_ST_IRQ_CTRL_2);
37946295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
380d8085222Sjohnnyhsu@realtek.com 	if (enable) {
381d8085222Sjohnnyhsu@realtek.com 		/* config one-bit depop parameter */
38246295e5eSKuninori Morimoto 		rt5631_write_index(component, RT5631_TEST_MODE_CTRL, 0x84c0);
38346295e5eSKuninori Morimoto 		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x309f);
38446295e5eSKuninori Morimoto 		rt5631_write_index(component, RT5631_CP_INTL_REG2, 0x6530);
385d8085222Sjohnnyhsu@realtek.com 		/* power on capless block */
38646295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_2,
387d8085222Sjohnnyhsu@realtek.com 				RT5631_EN_CAP_FREE_DEPOP);
388d8085222Sjohnnyhsu@realtek.com 	} else {
389d8085222Sjohnnyhsu@realtek.com 		/* power off capless block */
39046295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_2, 0);
391d8085222Sjohnnyhsu@realtek.com 		msleep(100);
392d8085222Sjohnnyhsu@realtek.com 	}
393d8085222Sjohnnyhsu@realtek.com 
394d8085222Sjohnnyhsu@realtek.com 	/* recover soft volume and zero crossing setting */
39546295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, soft_vol);
39646295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
397d8085222Sjohnnyhsu@realtek.com }
398d8085222Sjohnnyhsu@realtek.com 
399d8085222Sjohnnyhsu@realtek.com /**
400d8085222Sjohnnyhsu@realtek.com  * onebit_depop_mute_stage - auto depop in mute stage.
401762a3d43SPierre-Louis Bossart  * @component: ASoC component
402d8085222Sjohnnyhsu@realtek.com  * @enable: mute/unmute
403d8085222Sjohnnyhsu@realtek.com  *
404d8085222Sjohnnyhsu@realtek.com  * When mute/unmute headphone, the depop sequence is done by hardware.
405d8085222Sjohnnyhsu@realtek.com  */
onebit_depop_mute_stage(struct snd_soc_component * component,int enable)40646295e5eSKuninori Morimoto static void onebit_depop_mute_stage(struct snd_soc_component *component, int enable)
407d8085222Sjohnnyhsu@realtek.com {
408d8085222Sjohnnyhsu@realtek.com 	unsigned int soft_vol, hp_zc;
409d8085222Sjohnnyhsu@realtek.com 
410d8085222Sjohnnyhsu@realtek.com 	/* enable one-bit depop function */
41146295e5eSKuninori Morimoto 	snd_soc_component_update_bits(component, RT5631_DEPOP_FUN_CTRL_2,
412d8085222Sjohnnyhsu@realtek.com 				RT5631_EN_ONE_BIT_DEPOP, 0);
413d8085222Sjohnnyhsu@realtek.com 
414d8085222Sjohnnyhsu@realtek.com 	/* keep soft volume and zero crossing setting */
415467a2553SKuninori Morimoto 	soft_vol = snd_soc_component_read(component, RT5631_SOFT_VOL_CTRL);
41646295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, 0);
417467a2553SKuninori Morimoto 	hp_zc = snd_soc_component_read(component, RT5631_INT_ST_IRQ_CTRL_2);
41846295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
419d8085222Sjohnnyhsu@realtek.com 	if (enable) {
420d8085222Sjohnnyhsu@realtek.com 		schedule_timeout_uninterruptible(msecs_to_jiffies(10));
421d8085222Sjohnnyhsu@realtek.com 		/* config one-bit depop parameter */
42246295e5eSKuninori Morimoto 		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x307f);
42346295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_HP_OUT_VOL,
424d8085222Sjohnnyhsu@realtek.com 				RT5631_L_MUTE | RT5631_R_MUTE, 0);
425d8085222Sjohnnyhsu@realtek.com 		msleep(300);
426d8085222Sjohnnyhsu@realtek.com 	} else {
42746295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_HP_OUT_VOL,
428d8085222Sjohnnyhsu@realtek.com 			RT5631_L_MUTE | RT5631_R_MUTE,
429d8085222Sjohnnyhsu@realtek.com 			RT5631_L_MUTE | RT5631_R_MUTE);
430d8085222Sjohnnyhsu@realtek.com 		msleep(100);
431d8085222Sjohnnyhsu@realtek.com 	}
432d8085222Sjohnnyhsu@realtek.com 
433d8085222Sjohnnyhsu@realtek.com 	/* recover soft volume and zero crossing setting */
43446295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, soft_vol);
43546295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
436d8085222Sjohnnyhsu@realtek.com }
437d8085222Sjohnnyhsu@realtek.com 
438d8085222Sjohnnyhsu@realtek.com /**
43979d77f7fSPierre-Louis Bossart  * depop_seq_power_stage - step by step depop sequence in power stage.
440762a3d43SPierre-Louis Bossart  * @component: ASoC component
441d8085222Sjohnnyhsu@realtek.com  * @enable: power on/off
442d8085222Sjohnnyhsu@realtek.com  *
443d8085222Sjohnnyhsu@realtek.com  * When power on/off headphone, the depop sequence is done in step by step.
444d8085222Sjohnnyhsu@realtek.com  */
depop_seq_power_stage(struct snd_soc_component * component,int enable)44546295e5eSKuninori Morimoto static void depop_seq_power_stage(struct snd_soc_component *component, int enable)
446d8085222Sjohnnyhsu@realtek.com {
447d8085222Sjohnnyhsu@realtek.com 	unsigned int soft_vol, hp_zc;
448d8085222Sjohnnyhsu@realtek.com 
449d8085222Sjohnnyhsu@realtek.com 	/* depop control by register */
45046295e5eSKuninori Morimoto 	snd_soc_component_update_bits(component, RT5631_DEPOP_FUN_CTRL_2,
451d8085222Sjohnnyhsu@realtek.com 		RT5631_EN_ONE_BIT_DEPOP, RT5631_EN_ONE_BIT_DEPOP);
452d8085222Sjohnnyhsu@realtek.com 
453d8085222Sjohnnyhsu@realtek.com 	/* keep soft volume and zero crossing setting */
454467a2553SKuninori Morimoto 	soft_vol = snd_soc_component_read(component, RT5631_SOFT_VOL_CTRL);
45546295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, 0);
456467a2553SKuninori Morimoto 	hp_zc = snd_soc_component_read(component, RT5631_INT_ST_IRQ_CTRL_2);
45746295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
458d8085222Sjohnnyhsu@realtek.com 	if (enable) {
459d8085222Sjohnnyhsu@realtek.com 		/* config depop sequence parameter */
46046295e5eSKuninori Morimoto 		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x303e);
461d8085222Sjohnnyhsu@realtek.com 
462d8085222Sjohnnyhsu@realtek.com 		/* power on headphone and charge pump */
46346295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
464d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_CHARGE_PUMP | RT5631_PWR_HP_L_AMP |
465d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_HP_R_AMP,
466d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_CHARGE_PUMP | RT5631_PWR_HP_L_AMP |
467d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_HP_R_AMP);
468d8085222Sjohnnyhsu@realtek.com 
469d8085222Sjohnnyhsu@realtek.com 		/* power on soft generator and depop mode2 */
47046295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
471d8085222Sjohnnyhsu@realtek.com 			RT5631_POW_ON_SOFT_GEN | RT5631_EN_DEPOP2_FOR_HP);
472d8085222Sjohnnyhsu@realtek.com 		msleep(100);
473d8085222Sjohnnyhsu@realtek.com 
474d8085222Sjohnnyhsu@realtek.com 		/* stop depop mode */
47546295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
476d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_HP_DEPOP_DIS, RT5631_PWR_HP_DEPOP_DIS);
477d8085222Sjohnnyhsu@realtek.com 	} else {
478d8085222Sjohnnyhsu@realtek.com 		/* config depop sequence parameter */
47946295e5eSKuninori Morimoto 		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x303F);
48046295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
481d8085222Sjohnnyhsu@realtek.com 			RT5631_POW_ON_SOFT_GEN | RT5631_EN_MUTE_UNMUTE_DEPOP |
482d8085222Sjohnnyhsu@realtek.com 			RT5631_PD_HPAMP_L_ST_UP | RT5631_PD_HPAMP_R_ST_UP);
483d8085222Sjohnnyhsu@realtek.com 		msleep(75);
48446295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
485d8085222Sjohnnyhsu@realtek.com 			RT5631_POW_ON_SOFT_GEN | RT5631_PD_HPAMP_L_ST_UP |
486d8085222Sjohnnyhsu@realtek.com 			RT5631_PD_HPAMP_R_ST_UP);
487d8085222Sjohnnyhsu@realtek.com 
488d8085222Sjohnnyhsu@realtek.com 		/* start depop mode */
48946295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
490d8085222Sjohnnyhsu@realtek.com 				RT5631_PWR_HP_DEPOP_DIS, 0);
491d8085222Sjohnnyhsu@realtek.com 
492d8085222Sjohnnyhsu@realtek.com 		/* config depop sequence parameter */
49346295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
494d8085222Sjohnnyhsu@realtek.com 			RT5631_POW_ON_SOFT_GEN | RT5631_EN_DEPOP2_FOR_HP |
495d8085222Sjohnnyhsu@realtek.com 			RT5631_PD_HPAMP_L_ST_UP | RT5631_PD_HPAMP_R_ST_UP);
496d8085222Sjohnnyhsu@realtek.com 		msleep(80);
49746295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
498d8085222Sjohnnyhsu@realtek.com 			RT5631_POW_ON_SOFT_GEN);
499d8085222Sjohnnyhsu@realtek.com 
500d8085222Sjohnnyhsu@realtek.com 		/* power down headphone and charge pump */
50146295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
502d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_CHARGE_PUMP | RT5631_PWR_HP_L_AMP |
503d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_HP_R_AMP, 0);
504d8085222Sjohnnyhsu@realtek.com 	}
505d8085222Sjohnnyhsu@realtek.com 
506d8085222Sjohnnyhsu@realtek.com 	/* recover soft volume and zero crossing setting */
50746295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, soft_vol);
50846295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
509d8085222Sjohnnyhsu@realtek.com }
510d8085222Sjohnnyhsu@realtek.com 
511d8085222Sjohnnyhsu@realtek.com /**
512d8085222Sjohnnyhsu@realtek.com  * depop_seq_mute_stage - step by step depop sequence in mute stage.
513762a3d43SPierre-Louis Bossart  * @component: ASoC component
514d8085222Sjohnnyhsu@realtek.com  * @enable: mute/unmute
515d8085222Sjohnnyhsu@realtek.com  *
516d8085222Sjohnnyhsu@realtek.com  * When mute/unmute headphone, the depop sequence is done in step by step.
517d8085222Sjohnnyhsu@realtek.com  */
depop_seq_mute_stage(struct snd_soc_component * component,int enable)51846295e5eSKuninori Morimoto static void depop_seq_mute_stage(struct snd_soc_component *component, int enable)
519d8085222Sjohnnyhsu@realtek.com {
520d8085222Sjohnnyhsu@realtek.com 	unsigned int soft_vol, hp_zc;
521d8085222Sjohnnyhsu@realtek.com 
522d8085222Sjohnnyhsu@realtek.com 	/* depop control by register */
52346295e5eSKuninori Morimoto 	snd_soc_component_update_bits(component, RT5631_DEPOP_FUN_CTRL_2,
524d8085222Sjohnnyhsu@realtek.com 		RT5631_EN_ONE_BIT_DEPOP, RT5631_EN_ONE_BIT_DEPOP);
525d8085222Sjohnnyhsu@realtek.com 
526d8085222Sjohnnyhsu@realtek.com 	/* keep soft volume and zero crossing setting */
527467a2553SKuninori Morimoto 	soft_vol = snd_soc_component_read(component, RT5631_SOFT_VOL_CTRL);
52846295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, 0);
529467a2553SKuninori Morimoto 	hp_zc = snd_soc_component_read(component, RT5631_INT_ST_IRQ_CTRL_2);
53046295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc & 0xf7ff);
531d8085222Sjohnnyhsu@realtek.com 	if (enable) {
532d8085222Sjohnnyhsu@realtek.com 		schedule_timeout_uninterruptible(msecs_to_jiffies(10));
533d8085222Sjohnnyhsu@realtek.com 
534d8085222Sjohnnyhsu@realtek.com 		/* config depop sequence parameter */
53546295e5eSKuninori Morimoto 		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x302f);
53646295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
537d8085222Sjohnnyhsu@realtek.com 			RT5631_POW_ON_SOFT_GEN | RT5631_EN_MUTE_UNMUTE_DEPOP |
538d8085222Sjohnnyhsu@realtek.com 			RT5631_EN_HP_R_M_UN_MUTE_DEPOP |
539d8085222Sjohnnyhsu@realtek.com 			RT5631_EN_HP_L_M_UN_MUTE_DEPOP);
540d8085222Sjohnnyhsu@realtek.com 
54146295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_HP_OUT_VOL,
542d8085222Sjohnnyhsu@realtek.com 				RT5631_L_MUTE | RT5631_R_MUTE, 0);
543d8085222Sjohnnyhsu@realtek.com 		msleep(160);
544d8085222Sjohnnyhsu@realtek.com 	} else {
545d8085222Sjohnnyhsu@realtek.com 		/* config depop sequence parameter */
54646295e5eSKuninori Morimoto 		rt5631_write_index(component, RT5631_SPK_INTL_CTRL, 0x302f);
54746295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_DEPOP_FUN_CTRL_1,
548d8085222Sjohnnyhsu@realtek.com 			RT5631_POW_ON_SOFT_GEN | RT5631_EN_MUTE_UNMUTE_DEPOP |
549d8085222Sjohnnyhsu@realtek.com 			RT5631_EN_HP_R_M_UN_MUTE_DEPOP |
550d8085222Sjohnnyhsu@realtek.com 			RT5631_EN_HP_L_M_UN_MUTE_DEPOP);
551d8085222Sjohnnyhsu@realtek.com 
55246295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_HP_OUT_VOL,
553d8085222Sjohnnyhsu@realtek.com 			RT5631_L_MUTE | RT5631_R_MUTE,
554d8085222Sjohnnyhsu@realtek.com 			RT5631_L_MUTE | RT5631_R_MUTE);
555d8085222Sjohnnyhsu@realtek.com 		msleep(150);
556d8085222Sjohnnyhsu@realtek.com 	}
557d8085222Sjohnnyhsu@realtek.com 
558d8085222Sjohnnyhsu@realtek.com 	/* recover soft volume and zero crossing setting */
55946295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_SOFT_VOL_CTRL, soft_vol);
56046295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, hp_zc);
561d8085222Sjohnnyhsu@realtek.com }
562d8085222Sjohnnyhsu@realtek.com 
hp_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)563d8085222Sjohnnyhsu@realtek.com static int hp_event(struct snd_soc_dapm_widget *w,
564d8085222Sjohnnyhsu@realtek.com 	struct snd_kcontrol *kcontrol, int event)
565d8085222Sjohnnyhsu@realtek.com {
56646295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
56746295e5eSKuninori Morimoto 	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
568d8085222Sjohnnyhsu@realtek.com 
569d8085222Sjohnnyhsu@realtek.com 	switch (event) {
570d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_DAPM_PRE_PMD:
571d8085222Sjohnnyhsu@realtek.com 		if (rt5631->codec_version) {
57246295e5eSKuninori Morimoto 			onebit_depop_mute_stage(component, 0);
57346295e5eSKuninori Morimoto 			onebit_depop_power_stage(component, 0);
574d8085222Sjohnnyhsu@realtek.com 		} else {
57546295e5eSKuninori Morimoto 			depop_seq_mute_stage(component, 0);
57646295e5eSKuninori Morimoto 			depop_seq_power_stage(component, 0);
577d8085222Sjohnnyhsu@realtek.com 		}
578d8085222Sjohnnyhsu@realtek.com 		break;
579d8085222Sjohnnyhsu@realtek.com 
580d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_DAPM_POST_PMU:
581d8085222Sjohnnyhsu@realtek.com 		if (rt5631->codec_version) {
58246295e5eSKuninori Morimoto 			onebit_depop_power_stage(component, 1);
58346295e5eSKuninori Morimoto 			onebit_depop_mute_stage(component, 1);
584d8085222Sjohnnyhsu@realtek.com 		} else {
58546295e5eSKuninori Morimoto 			depop_seq_power_stage(component, 1);
58646295e5eSKuninori Morimoto 			depop_seq_mute_stage(component, 1);
587d8085222Sjohnnyhsu@realtek.com 		}
588d8085222Sjohnnyhsu@realtek.com 		break;
589d8085222Sjohnnyhsu@realtek.com 
590d8085222Sjohnnyhsu@realtek.com 	default:
591d8085222Sjohnnyhsu@realtek.com 		break;
592d8085222Sjohnnyhsu@realtek.com 	}
593d8085222Sjohnnyhsu@realtek.com 
594d8085222Sjohnnyhsu@realtek.com 	return 0;
595d8085222Sjohnnyhsu@realtek.com }
596d8085222Sjohnnyhsu@realtek.com 
set_dmic_params(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)597d8085222Sjohnnyhsu@realtek.com static int set_dmic_params(struct snd_soc_dapm_widget *w,
598d8085222Sjohnnyhsu@realtek.com 	struct snd_kcontrol *kcontrol, int event)
599d8085222Sjohnnyhsu@realtek.com {
60046295e5eSKuninori Morimoto 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
60146295e5eSKuninori Morimoto 	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
602d8085222Sjohnnyhsu@realtek.com 
603d8085222Sjohnnyhsu@realtek.com 	switch (rt5631->rx_rate) {
604d8085222Sjohnnyhsu@realtek.com 	case 44100:
605d8085222Sjohnnyhsu@realtek.com 	case 48000:
60646295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_DIG_MIC_CTRL,
607d8085222Sjohnnyhsu@realtek.com 			RT5631_DMIC_CLK_CTRL_MASK,
608d8085222Sjohnnyhsu@realtek.com 			RT5631_DMIC_CLK_CTRL_TO_32FS);
609d8085222Sjohnnyhsu@realtek.com 		break;
610d8085222Sjohnnyhsu@realtek.com 
611d8085222Sjohnnyhsu@realtek.com 	case 32000:
612d8085222Sjohnnyhsu@realtek.com 	case 22050:
61346295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_DIG_MIC_CTRL,
614d8085222Sjohnnyhsu@realtek.com 			RT5631_DMIC_CLK_CTRL_MASK,
615d8085222Sjohnnyhsu@realtek.com 			RT5631_DMIC_CLK_CTRL_TO_64FS);
616d8085222Sjohnnyhsu@realtek.com 		break;
617d8085222Sjohnnyhsu@realtek.com 
618d8085222Sjohnnyhsu@realtek.com 	case 16000:
619d8085222Sjohnnyhsu@realtek.com 	case 11025:
620d8085222Sjohnnyhsu@realtek.com 	case 8000:
62146295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_DIG_MIC_CTRL,
622d8085222Sjohnnyhsu@realtek.com 			RT5631_DMIC_CLK_CTRL_MASK,
623d8085222Sjohnnyhsu@realtek.com 			RT5631_DMIC_CLK_CTRL_TO_128FS);
624d8085222Sjohnnyhsu@realtek.com 		break;
625d8085222Sjohnnyhsu@realtek.com 
626d8085222Sjohnnyhsu@realtek.com 	default:
627d8085222Sjohnnyhsu@realtek.com 		return -EINVAL;
628d8085222Sjohnnyhsu@realtek.com 	}
629d8085222Sjohnnyhsu@realtek.com 
630d8085222Sjohnnyhsu@realtek.com 	return 0;
631d8085222Sjohnnyhsu@realtek.com }
632d8085222Sjohnnyhsu@realtek.com 
633d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_recmixl_mixer_controls[] = {
634d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("OUTMIXL Capture Switch", RT5631_ADC_REC_MIXER,
635d8085222Sjohnnyhsu@realtek.com 			RT5631_M_OUTMIXL_RECMIXL_BIT, 1, 1),
636d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC1_BST1 Capture Switch", RT5631_ADC_REC_MIXER,
637d8085222Sjohnnyhsu@realtek.com 			RT5631_M_MIC1_RECMIXL_BIT, 1, 1),
638d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("AXILVOL Capture Switch", RT5631_ADC_REC_MIXER,
639d8085222Sjohnnyhsu@realtek.com 			RT5631_M_AXIL_RECMIXL_BIT, 1, 1),
640d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MONOIN_RX Capture Switch", RT5631_ADC_REC_MIXER,
641d8085222Sjohnnyhsu@realtek.com 			RT5631_M_MONO_IN_RECMIXL_BIT, 1, 1),
642d8085222Sjohnnyhsu@realtek.com };
643d8085222Sjohnnyhsu@realtek.com 
644d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_recmixr_mixer_controls[] = {
645d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MONOIN_RX Capture Switch", RT5631_ADC_REC_MIXER,
646d8085222Sjohnnyhsu@realtek.com 			RT5631_M_MONO_IN_RECMIXR_BIT, 1, 1),
647d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("AXIRVOL Capture Switch", RT5631_ADC_REC_MIXER,
648d8085222Sjohnnyhsu@realtek.com 			RT5631_M_AXIR_RECMIXR_BIT, 1, 1),
649d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC2_BST2 Capture Switch", RT5631_ADC_REC_MIXER,
650d8085222Sjohnnyhsu@realtek.com 			RT5631_M_MIC2_RECMIXR_BIT, 1, 1),
651d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("OUTMIXR Capture Switch", RT5631_ADC_REC_MIXER,
652d8085222Sjohnnyhsu@realtek.com 			RT5631_M_OUTMIXR_RECMIXR_BIT, 1, 1),
653d8085222Sjohnnyhsu@realtek.com };
654d8085222Sjohnnyhsu@realtek.com 
655d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_spkmixl_mixer_controls[] = {
656d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("RECMIXL Playback Switch", RT5631_SPK_MIXER_CTRL,
657d8085222Sjohnnyhsu@realtek.com 			RT5631_M_RECMIXL_SPKMIXL_BIT, 1, 1),
658d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC1_P Playback Switch", RT5631_SPK_MIXER_CTRL,
659d8085222Sjohnnyhsu@realtek.com 			RT5631_M_MIC1P_SPKMIXL_BIT, 1, 1),
660d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("DACL Playback Switch", RT5631_SPK_MIXER_CTRL,
661d8085222Sjohnnyhsu@realtek.com 			RT5631_M_DACL_SPKMIXL_BIT, 1, 1),
662d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("OUTMIXL Playback Switch", RT5631_SPK_MIXER_CTRL,
663d8085222Sjohnnyhsu@realtek.com 			RT5631_M_OUTMIXL_SPKMIXL_BIT, 1, 1),
664d8085222Sjohnnyhsu@realtek.com };
665d8085222Sjohnnyhsu@realtek.com 
666d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_spkmixr_mixer_controls[] = {
667d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("OUTMIXR Playback Switch", RT5631_SPK_MIXER_CTRL,
668d8085222Sjohnnyhsu@realtek.com 			RT5631_M_OUTMIXR_SPKMIXR_BIT, 1, 1),
669d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("DACR Playback Switch", RT5631_SPK_MIXER_CTRL,
670d8085222Sjohnnyhsu@realtek.com 			RT5631_M_DACR_SPKMIXR_BIT, 1, 1),
671d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC2_P Playback Switch", RT5631_SPK_MIXER_CTRL,
672d8085222Sjohnnyhsu@realtek.com 			RT5631_M_MIC2P_SPKMIXR_BIT, 1, 1),
673d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("RECMIXR Playback Switch", RT5631_SPK_MIXER_CTRL,
674d8085222Sjohnnyhsu@realtek.com 			RT5631_M_RECMIXR_SPKMIXR_BIT, 1, 1),
675d8085222Sjohnnyhsu@realtek.com };
676d8085222Sjohnnyhsu@realtek.com 
677d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_outmixl_mixer_controls[] = {
678d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("RECMIXL Playback Switch", RT5631_OUTMIXER_L_CTRL,
679d8085222Sjohnnyhsu@realtek.com 				RT5631_M_RECMIXL_OUTMIXL_BIT, 1, 1),
680d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("RECMIXR Playback Switch", RT5631_OUTMIXER_L_CTRL,
681d8085222Sjohnnyhsu@realtek.com 				RT5631_M_RECMIXR_OUTMIXL_BIT, 1, 1),
682d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("DACL Playback Switch", RT5631_OUTMIXER_L_CTRL,
683d8085222Sjohnnyhsu@realtek.com 				RT5631_M_DACL_OUTMIXL_BIT, 1, 1),
684d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_OUTMIXER_L_CTRL,
685d8085222Sjohnnyhsu@realtek.com 				RT5631_M_MIC1_OUTMIXL_BIT, 1, 1),
686d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_OUTMIXER_L_CTRL,
687d8085222Sjohnnyhsu@realtek.com 				RT5631_M_MIC2_OUTMIXL_BIT, 1, 1),
688d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MONOIN_RXP Playback Switch", RT5631_OUTMIXER_L_CTRL,
689d8085222Sjohnnyhsu@realtek.com 				RT5631_M_MONO_INP_OUTMIXL_BIT, 1, 1),
690d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("AXILVOL Playback Switch", RT5631_OUTMIXER_L_CTRL,
691d8085222Sjohnnyhsu@realtek.com 				RT5631_M_AXIL_OUTMIXL_BIT, 1, 1),
692d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("AXIRVOL Playback Switch", RT5631_OUTMIXER_L_CTRL,
693d8085222Sjohnnyhsu@realtek.com 				RT5631_M_AXIR_OUTMIXL_BIT, 1, 1),
694d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("VDAC Playback Switch", RT5631_OUTMIXER_L_CTRL,
695d8085222Sjohnnyhsu@realtek.com 				RT5631_M_VDAC_OUTMIXL_BIT, 1, 1),
696d8085222Sjohnnyhsu@realtek.com };
697d8085222Sjohnnyhsu@realtek.com 
698d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_outmixr_mixer_controls[] = {
699d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("VDAC Playback Switch", RT5631_OUTMIXER_R_CTRL,
700d8085222Sjohnnyhsu@realtek.com 				RT5631_M_VDAC_OUTMIXR_BIT, 1, 1),
701d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("AXIRVOL Playback Switch", RT5631_OUTMIXER_R_CTRL,
702d8085222Sjohnnyhsu@realtek.com 				RT5631_M_AXIR_OUTMIXR_BIT, 1, 1),
703d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("AXILVOL Playback Switch", RT5631_OUTMIXER_R_CTRL,
704d8085222Sjohnnyhsu@realtek.com 				RT5631_M_AXIL_OUTMIXR_BIT, 1, 1),
705d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MONOIN_RXN Playback Switch", RT5631_OUTMIXER_R_CTRL,
706d8085222Sjohnnyhsu@realtek.com 				RT5631_M_MONO_INN_OUTMIXR_BIT, 1, 1),
707d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_OUTMIXER_R_CTRL,
708d8085222Sjohnnyhsu@realtek.com 				RT5631_M_MIC2_OUTMIXR_BIT, 1, 1),
709d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_OUTMIXER_R_CTRL,
710d8085222Sjohnnyhsu@realtek.com 				RT5631_M_MIC1_OUTMIXR_BIT, 1, 1),
711d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("DACR Playback Switch", RT5631_OUTMIXER_R_CTRL,
712d8085222Sjohnnyhsu@realtek.com 				RT5631_M_DACR_OUTMIXR_BIT, 1, 1),
713d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("RECMIXR Playback Switch", RT5631_OUTMIXER_R_CTRL,
714d8085222Sjohnnyhsu@realtek.com 				RT5631_M_RECMIXR_OUTMIXR_BIT, 1, 1),
715d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("RECMIXL Playback Switch", RT5631_OUTMIXER_R_CTRL,
716d8085222Sjohnnyhsu@realtek.com 				RT5631_M_RECMIXL_OUTMIXR_BIT, 1, 1),
717d8085222Sjohnnyhsu@realtek.com };
718d8085222Sjohnnyhsu@realtek.com 
719d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_AXO1MIX_mixer_controls[] = {
720d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_AXO1MIXER_CTRL,
721d8085222Sjohnnyhsu@realtek.com 				RT5631_M_MIC1_AXO1MIX_BIT , 1, 1),
722d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_AXO1MIXER_CTRL,
723d8085222Sjohnnyhsu@realtek.com 				RT5631_M_MIC2_AXO1MIX_BIT, 1, 1),
724d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("OUTVOLL Playback Switch", RT5631_AXO1MIXER_CTRL,
725d8085222Sjohnnyhsu@realtek.com 				RT5631_M_OUTMIXL_AXO1MIX_BIT , 1 , 1),
726d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("OUTVOLR Playback Switch", RT5631_AXO1MIXER_CTRL,
727d8085222Sjohnnyhsu@realtek.com 				RT5631_M_OUTMIXR_AXO1MIX_BIT, 1, 1),
728d8085222Sjohnnyhsu@realtek.com };
729d8085222Sjohnnyhsu@realtek.com 
730d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_AXO2MIX_mixer_controls[] = {
731d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC1_BST1 Playback Switch", RT5631_AXO2MIXER_CTRL,
732d8085222Sjohnnyhsu@realtek.com 				RT5631_M_MIC1_AXO2MIX_BIT, 1, 1),
733d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("MIC2_BST2 Playback Switch", RT5631_AXO2MIXER_CTRL,
734d8085222Sjohnnyhsu@realtek.com 				RT5631_M_MIC2_AXO2MIX_BIT, 1, 1),
735d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("OUTVOLL Playback Switch", RT5631_AXO2MIXER_CTRL,
736d8085222Sjohnnyhsu@realtek.com 				RT5631_M_OUTMIXL_AXO2MIX_BIT, 1, 1),
737d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("OUTVOLR Playback Switch", RT5631_AXO2MIXER_CTRL,
738d8085222Sjohnnyhsu@realtek.com 				RT5631_M_OUTMIXR_AXO2MIX_BIT, 1 , 1),
739d8085222Sjohnnyhsu@realtek.com };
740d8085222Sjohnnyhsu@realtek.com 
741d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_spolmix_mixer_controls[] = {
742d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("SPKVOLL Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
743d8085222Sjohnnyhsu@realtek.com 				RT5631_M_SPKVOLL_SPOLMIX_BIT, 1, 1),
744d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("SPKVOLR Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
745d8085222Sjohnnyhsu@realtek.com 				RT5631_M_SPKVOLR_SPOLMIX_BIT, 1, 1),
746d8085222Sjohnnyhsu@realtek.com };
747d8085222Sjohnnyhsu@realtek.com 
748d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_spormix_mixer_controls[] = {
749d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("SPKVOLL Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
750d8085222Sjohnnyhsu@realtek.com 				RT5631_M_SPKVOLL_SPORMIX_BIT, 1, 1),
751d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("SPKVOLR Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
752d8085222Sjohnnyhsu@realtek.com 				RT5631_M_SPKVOLR_SPORMIX_BIT, 1, 1),
753d8085222Sjohnnyhsu@realtek.com };
754d8085222Sjohnnyhsu@realtek.com 
755d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_monomix_mixer_controls[] = {
756d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("OUTVOLL Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
757d8085222Sjohnnyhsu@realtek.com 				RT5631_M_OUTVOLL_MONOMIX_BIT, 1, 1),
758d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_SINGLE("OUTVOLR Playback Switch", RT5631_SPK_MONO_OUT_CTRL,
759d8085222Sjohnnyhsu@realtek.com 				RT5631_M_OUTVOLR_MONOMIX_BIT, 1, 1),
760d8085222Sjohnnyhsu@realtek.com };
761d8085222Sjohnnyhsu@realtek.com 
762d8085222Sjohnnyhsu@realtek.com /* Left SPK Volume Input */
763d8085222Sjohnnyhsu@realtek.com static const char *rt5631_spkvoll_sel[] = {"Vmid", "SPKMIXL"};
764d8085222Sjohnnyhsu@realtek.com 
765f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_spkvoll_enum, RT5631_SPK_OUT_VOL,
766d8085222Sjohnnyhsu@realtek.com 			    RT5631_L_EN_SHIFT, rt5631_spkvoll_sel);
767d8085222Sjohnnyhsu@realtek.com 
768d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_spkvoll_mux_control =
769d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_ENUM("Left SPKVOL SRC", rt5631_spkvoll_enum);
770d8085222Sjohnnyhsu@realtek.com 
771d8085222Sjohnnyhsu@realtek.com /* Left HP Volume Input */
772d8085222Sjohnnyhsu@realtek.com static const char *rt5631_hpvoll_sel[] = {"Vmid", "OUTMIXL"};
773d8085222Sjohnnyhsu@realtek.com 
774f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_hpvoll_enum, RT5631_HP_OUT_VOL,
775d8085222Sjohnnyhsu@realtek.com 			    RT5631_L_EN_SHIFT, rt5631_hpvoll_sel);
776d8085222Sjohnnyhsu@realtek.com 
777d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_hpvoll_mux_control =
778d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_ENUM("Left HPVOL SRC", rt5631_hpvoll_enum);
779d8085222Sjohnnyhsu@realtek.com 
780d8085222Sjohnnyhsu@realtek.com /* Left Out Volume Input */
781d8085222Sjohnnyhsu@realtek.com static const char *rt5631_outvoll_sel[] = {"Vmid", "OUTMIXL"};
782d8085222Sjohnnyhsu@realtek.com 
783f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_outvoll_enum, RT5631_MONO_AXO_1_2_VOL,
784d8085222Sjohnnyhsu@realtek.com 			    RT5631_L_EN_SHIFT, rt5631_outvoll_sel);
785d8085222Sjohnnyhsu@realtek.com 
786d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_outvoll_mux_control =
787d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_ENUM("Left OUTVOL SRC", rt5631_outvoll_enum);
788d8085222Sjohnnyhsu@realtek.com 
789d8085222Sjohnnyhsu@realtek.com /* Right Out Volume Input */
790d8085222Sjohnnyhsu@realtek.com static const char *rt5631_outvolr_sel[] = {"Vmid", "OUTMIXR"};
791d8085222Sjohnnyhsu@realtek.com 
792f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_outvolr_enum, RT5631_MONO_AXO_1_2_VOL,
793d8085222Sjohnnyhsu@realtek.com 			    RT5631_R_EN_SHIFT, rt5631_outvolr_sel);
794d8085222Sjohnnyhsu@realtek.com 
795d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_outvolr_mux_control =
796d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_ENUM("Right OUTVOL SRC", rt5631_outvolr_enum);
797d8085222Sjohnnyhsu@realtek.com 
798d8085222Sjohnnyhsu@realtek.com /* Right HP Volume Input */
799d8085222Sjohnnyhsu@realtek.com static const char *rt5631_hpvolr_sel[] = {"Vmid", "OUTMIXR"};
800d8085222Sjohnnyhsu@realtek.com 
801f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_hpvolr_enum, RT5631_HP_OUT_VOL,
802d8085222Sjohnnyhsu@realtek.com 			    RT5631_R_EN_SHIFT, rt5631_hpvolr_sel);
803d8085222Sjohnnyhsu@realtek.com 
804d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_hpvolr_mux_control =
805d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_ENUM("Right HPVOL SRC", rt5631_hpvolr_enum);
806d8085222Sjohnnyhsu@realtek.com 
807d8085222Sjohnnyhsu@realtek.com /* Right SPK Volume Input */
808d8085222Sjohnnyhsu@realtek.com static const char *rt5631_spkvolr_sel[] = {"Vmid", "SPKMIXR"};
809d8085222Sjohnnyhsu@realtek.com 
810f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_spkvolr_enum, RT5631_SPK_OUT_VOL,
811d8085222Sjohnnyhsu@realtek.com 			    RT5631_R_EN_SHIFT, rt5631_spkvolr_sel);
812d8085222Sjohnnyhsu@realtek.com 
813d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_spkvolr_mux_control =
814d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_ENUM("Right SPKVOL SRC", rt5631_spkvolr_enum);
815d8085222Sjohnnyhsu@realtek.com 
816d8085222Sjohnnyhsu@realtek.com /* SPO Left Channel Input */
817d8085222Sjohnnyhsu@realtek.com static const char *rt5631_spol_src_sel[] = {
818d8085222Sjohnnyhsu@realtek.com 	"SPOLMIX", "MONOIN_RX", "VDAC", "DACL"};
819d8085222Sjohnnyhsu@realtek.com 
820f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_spol_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
821d8085222Sjohnnyhsu@realtek.com 			    RT5631_SPK_L_MUX_SEL_SHIFT, rt5631_spol_src_sel);
822d8085222Sjohnnyhsu@realtek.com 
823d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_spol_mux_control =
824d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_ENUM("SPOL SRC", rt5631_spol_src_enum);
825d8085222Sjohnnyhsu@realtek.com 
826d8085222Sjohnnyhsu@realtek.com /* SPO Right Channel Input */
827d8085222Sjohnnyhsu@realtek.com static const char *rt5631_spor_src_sel[] = {
828d8085222Sjohnnyhsu@realtek.com 	"SPORMIX", "MONOIN_RX", "VDAC", "DACR"};
829d8085222Sjohnnyhsu@realtek.com 
830f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_spor_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
831d8085222Sjohnnyhsu@realtek.com 			    RT5631_SPK_R_MUX_SEL_SHIFT, rt5631_spor_src_sel);
832d8085222Sjohnnyhsu@realtek.com 
833d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_spor_mux_control =
834d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_ENUM("SPOR SRC", rt5631_spor_src_enum);
835d8085222Sjohnnyhsu@realtek.com 
836d8085222Sjohnnyhsu@realtek.com /* MONO Input */
837d8085222Sjohnnyhsu@realtek.com static const char *rt5631_mono_src_sel[] = {"MONOMIX", "MONOIN_RX", "VDAC"};
838d8085222Sjohnnyhsu@realtek.com 
839f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_mono_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
840d8085222Sjohnnyhsu@realtek.com 			    RT5631_MONO_MUX_SEL_SHIFT, rt5631_mono_src_sel);
841d8085222Sjohnnyhsu@realtek.com 
842d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_mono_mux_control =
843d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_ENUM("MONO SRC", rt5631_mono_src_enum);
844d8085222Sjohnnyhsu@realtek.com 
845d8085222Sjohnnyhsu@realtek.com /* Left HPO Input */
846d8085222Sjohnnyhsu@realtek.com static const char *rt5631_hpl_src_sel[] = {"Left HPVOL", "Left DAC"};
847d8085222Sjohnnyhsu@realtek.com 
848f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_hpl_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
849d8085222Sjohnnyhsu@realtek.com 			    RT5631_HP_L_MUX_SEL_SHIFT, rt5631_hpl_src_sel);
850d8085222Sjohnnyhsu@realtek.com 
851d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_hpl_mux_control =
852d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_ENUM("HPL SRC", rt5631_hpl_src_enum);
853d8085222Sjohnnyhsu@realtek.com 
854d8085222Sjohnnyhsu@realtek.com /* Right HPO Input */
855d8085222Sjohnnyhsu@realtek.com static const char *rt5631_hpr_src_sel[] = {"Right HPVOL", "Right DAC"};
856d8085222Sjohnnyhsu@realtek.com 
857f843cdf2STakashi Iwai static SOC_ENUM_SINGLE_DECL(rt5631_hpr_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
858d8085222Sjohnnyhsu@realtek.com 			    RT5631_HP_R_MUX_SEL_SHIFT, rt5631_hpr_src_sel);
859d8085222Sjohnnyhsu@realtek.com 
860d8085222Sjohnnyhsu@realtek.com static const struct snd_kcontrol_new rt5631_hpr_mux_control =
861d8085222Sjohnnyhsu@realtek.com 	SOC_DAPM_ENUM("HPR SRC", rt5631_hpr_src_enum);
862d8085222Sjohnnyhsu@realtek.com 
863d8085222Sjohnnyhsu@realtek.com static const struct snd_soc_dapm_widget rt5631_dapm_widgets[] = {
864d8085222Sjohnnyhsu@realtek.com 	/* Vmid */
865d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_VMID("Vmid"),
866d8085222Sjohnnyhsu@realtek.com 	/* PLL1 */
867d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_SUPPLY("PLL1", RT5631_PWR_MANAG_ADD2,
868d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_PLL1_BIT, 0, NULL, 0),
869d8085222Sjohnnyhsu@realtek.com 
870d8085222Sjohnnyhsu@realtek.com 	/* Input Side */
871d8085222Sjohnnyhsu@realtek.com 	/* Input Lines */
872d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_INPUT("MIC1"),
873d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_INPUT("MIC2"),
874d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_INPUT("AXIL"),
875d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_INPUT("AXIR"),
876d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_INPUT("MONOIN_RXN"),
877d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_INPUT("MONOIN_RXP"),
878d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_INPUT("DMIC"),
879d8085222Sjohnnyhsu@realtek.com 
880d8085222Sjohnnyhsu@realtek.com 	/* MICBIAS */
881d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MICBIAS("MIC Bias1", RT5631_PWR_MANAG_ADD2,
882d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_MICBIAS1_VOL_BIT, 0),
883d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MICBIAS("MIC Bias2", RT5631_PWR_MANAG_ADD2,
884d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_MICBIAS2_VOL_BIT, 0),
885d8085222Sjohnnyhsu@realtek.com 
886d8085222Sjohnnyhsu@realtek.com 	/* Boost */
887d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_PGA("MIC1 Boost", RT5631_PWR_MANAG_ADD2,
888d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_MIC1_BOOT_GAIN_BIT, 0, NULL, 0),
889d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_PGA("MIC2 Boost", RT5631_PWR_MANAG_ADD2,
890d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_MIC2_BOOT_GAIN_BIT, 0, NULL, 0),
891d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_PGA("MONOIN_RXP Boost", RT5631_PWR_MANAG_ADD4,
892d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_MONO_IN_P_VOL_BIT, 0, NULL, 0),
893d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_PGA("MONOIN_RXN Boost", RT5631_PWR_MANAG_ADD4,
894d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_MONO_IN_N_VOL_BIT, 0, NULL, 0),
895d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_PGA("AXIL Boost", RT5631_PWR_MANAG_ADD4,
896d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_AXIL_IN_VOL_BIT, 0, NULL, 0),
897d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_PGA("AXIR Boost", RT5631_PWR_MANAG_ADD4,
898d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_AXIR_IN_VOL_BIT, 0, NULL, 0),
899d8085222Sjohnnyhsu@realtek.com 
900d8085222Sjohnnyhsu@realtek.com 	/* MONO In */
901d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("MONO_IN", SND_SOC_NOPM, 0, 0, NULL, 0),
902d8085222Sjohnnyhsu@realtek.com 
903d8085222Sjohnnyhsu@realtek.com 	/* REC Mixer */
904d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("RECMIXL Mixer", RT5631_PWR_MANAG_ADD2,
905d8085222Sjohnnyhsu@realtek.com 		RT5631_PWR_RECMIXER_L_BIT, 0,
906d8085222Sjohnnyhsu@realtek.com 		&rt5631_recmixl_mixer_controls[0],
907d8085222Sjohnnyhsu@realtek.com 		ARRAY_SIZE(rt5631_recmixl_mixer_controls)),
908d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("RECMIXR Mixer", RT5631_PWR_MANAG_ADD2,
909d8085222Sjohnnyhsu@realtek.com 		RT5631_PWR_RECMIXER_R_BIT, 0,
910d8085222Sjohnnyhsu@realtek.com 		&rt5631_recmixr_mixer_controls[0],
911d8085222Sjohnnyhsu@realtek.com 		ARRAY_SIZE(rt5631_recmixr_mixer_controls)),
912d8085222Sjohnnyhsu@realtek.com 	/* Because of record duplication for L/R channel,
913d8085222Sjohnnyhsu@realtek.com 	 * L/R ADCs need power up at the same time */
914d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("ADC Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
915d8085222Sjohnnyhsu@realtek.com 
916d8085222Sjohnnyhsu@realtek.com 	/* DMIC */
917d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_SUPPLY("DMIC Supply", RT5631_DIG_MIC_CTRL,
918d8085222Sjohnnyhsu@realtek.com 		RT5631_DMIC_ENA_SHIFT, 0,
919d8085222Sjohnnyhsu@realtek.com 		set_dmic_params, SND_SOC_DAPM_PRE_PMU),
920d8085222Sjohnnyhsu@realtek.com 	/* ADC Data Srouce */
921d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_SUPPLY("Left ADC Select", RT5631_INT_ST_IRQ_CTRL_2,
922d8085222Sjohnnyhsu@realtek.com 			RT5631_ADC_DATA_SEL_MIC1_SHIFT, 0, NULL, 0),
923d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_SUPPLY("Right ADC Select", RT5631_INT_ST_IRQ_CTRL_2,
924d8085222Sjohnnyhsu@realtek.com 			RT5631_ADC_DATA_SEL_MIC2_SHIFT, 0, NULL, 0),
925d8085222Sjohnnyhsu@realtek.com 
926d8085222Sjohnnyhsu@realtek.com 	/* ADCs */
927d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_ADC("Left ADC", "HIFI Capture",
928d8085222Sjohnnyhsu@realtek.com 		RT5631_PWR_MANAG_ADD1, RT5631_PWR_ADC_L_CLK_BIT, 0),
929d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_ADC("Right ADC", "HIFI Capture",
930d8085222Sjohnnyhsu@realtek.com 		RT5631_PWR_MANAG_ADD1, RT5631_PWR_ADC_R_CLK_BIT, 0),
931d8085222Sjohnnyhsu@realtek.com 
932d8085222Sjohnnyhsu@realtek.com 	/* DAC and ADC supply power */
933d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_SUPPLY("I2S", RT5631_PWR_MANAG_ADD1,
934d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_MAIN_I2S_BIT, 0, NULL, 0),
935d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_SUPPLY("DAC REF", RT5631_PWR_MANAG_ADD1,
936d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_DAC_REF_BIT, 0, NULL, 0),
937d8085222Sjohnnyhsu@realtek.com 
938d8085222Sjohnnyhsu@realtek.com 	/* Output Side */
939d8085222Sjohnnyhsu@realtek.com 	/* DACs */
940d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_DAC("Left DAC", "HIFI Playback",
941d8085222Sjohnnyhsu@realtek.com 		RT5631_PWR_MANAG_ADD1, RT5631_PWR_DAC_L_CLK_BIT, 0),
942d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_DAC("Right DAC", "HIFI Playback",
943d8085222Sjohnnyhsu@realtek.com 		RT5631_PWR_MANAG_ADD1, RT5631_PWR_DAC_R_CLK_BIT, 0),
944d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_DAC("Voice DAC", "Voice DAC Mono Playback",
945d8085222Sjohnnyhsu@realtek.com 				SND_SOC_NOPM, 0, 0),
946d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_PGA("Voice DAC Boost", SND_SOC_NOPM, 0, 0, NULL, 0),
947d8085222Sjohnnyhsu@realtek.com 	/* DAC supply power */
948d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_SUPPLY("Left DAC To Mixer", RT5631_PWR_MANAG_ADD1,
949d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_DAC_L_TO_MIXER_BIT, 0, NULL, 0),
950d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_SUPPLY("Right DAC To Mixer", RT5631_PWR_MANAG_ADD1,
951d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_DAC_R_TO_MIXER_BIT, 0, NULL, 0),
952d8085222Sjohnnyhsu@realtek.com 
953d8085222Sjohnnyhsu@realtek.com 	/* Left SPK Mixer */
954d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("SPKMIXL Mixer", RT5631_PWR_MANAG_ADD2,
955d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_SPKMIXER_L_BIT, 0,
956d8085222Sjohnnyhsu@realtek.com 			&rt5631_spkmixl_mixer_controls[0],
957d8085222Sjohnnyhsu@realtek.com 			ARRAY_SIZE(rt5631_spkmixl_mixer_controls)),
958d8085222Sjohnnyhsu@realtek.com 	/* Left Out Mixer */
959d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("OUTMIXL Mixer", RT5631_PWR_MANAG_ADD2,
960d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_OUTMIXER_L_BIT, 0,
961d8085222Sjohnnyhsu@realtek.com 			&rt5631_outmixl_mixer_controls[0],
962d8085222Sjohnnyhsu@realtek.com 			ARRAY_SIZE(rt5631_outmixl_mixer_controls)),
963d8085222Sjohnnyhsu@realtek.com 	/* Right Out Mixer */
964d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("OUTMIXR Mixer", RT5631_PWR_MANAG_ADD2,
965d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_OUTMIXER_R_BIT, 0,
966d8085222Sjohnnyhsu@realtek.com 			&rt5631_outmixr_mixer_controls[0],
967d8085222Sjohnnyhsu@realtek.com 			ARRAY_SIZE(rt5631_outmixr_mixer_controls)),
968d8085222Sjohnnyhsu@realtek.com 	/* Right SPK Mixer */
969d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("SPKMIXR Mixer", RT5631_PWR_MANAG_ADD2,
970d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_SPKMIXER_R_BIT, 0,
971d8085222Sjohnnyhsu@realtek.com 			&rt5631_spkmixr_mixer_controls[0],
972d8085222Sjohnnyhsu@realtek.com 			ARRAY_SIZE(rt5631_spkmixr_mixer_controls)),
973d8085222Sjohnnyhsu@realtek.com 
974d8085222Sjohnnyhsu@realtek.com 	/* Volume Mux */
975d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MUX("Left SPKVOL Mux", RT5631_PWR_MANAG_ADD4,
976d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_SPK_L_VOL_BIT, 0,
977d8085222Sjohnnyhsu@realtek.com 			&rt5631_spkvoll_mux_control),
978d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MUX("Left HPVOL Mux", RT5631_PWR_MANAG_ADD4,
979d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_HP_L_OUT_VOL_BIT, 0,
980d8085222Sjohnnyhsu@realtek.com 			&rt5631_hpvoll_mux_control),
981d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MUX("Left OUTVOL Mux", RT5631_PWR_MANAG_ADD4,
982d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_LOUT_VOL_BIT, 0,
983d8085222Sjohnnyhsu@realtek.com 			&rt5631_outvoll_mux_control),
984d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MUX("Right OUTVOL Mux", RT5631_PWR_MANAG_ADD4,
985d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_ROUT_VOL_BIT, 0,
986d8085222Sjohnnyhsu@realtek.com 			&rt5631_outvolr_mux_control),
987d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MUX("Right HPVOL Mux", RT5631_PWR_MANAG_ADD4,
988d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_HP_R_OUT_VOL_BIT, 0,
989d8085222Sjohnnyhsu@realtek.com 			&rt5631_hpvolr_mux_control),
990d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MUX("Right SPKVOL Mux", RT5631_PWR_MANAG_ADD4,
991d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_SPK_R_VOL_BIT, 0,
992d8085222Sjohnnyhsu@realtek.com 			&rt5631_spkvolr_mux_control),
993d8085222Sjohnnyhsu@realtek.com 
994d8085222Sjohnnyhsu@realtek.com 	/* DAC To HP */
995d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_PGA_S("Left DAC_HP", 0, SND_SOC_NOPM, 0, 0, NULL, 0),
996d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_PGA_S("Right DAC_HP", 0, SND_SOC_NOPM, 0, 0, NULL, 0),
997d8085222Sjohnnyhsu@realtek.com 
998d8085222Sjohnnyhsu@realtek.com 	/* HP Depop */
999d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_PGA_S("HP Depop", 1, SND_SOC_NOPM, 0, 0,
1000d8085222Sjohnnyhsu@realtek.com 		hp_event, SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
1001d8085222Sjohnnyhsu@realtek.com 
1002d8085222Sjohnnyhsu@realtek.com 	/* AXO1 Mixer */
1003d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("AXO1MIX Mixer", RT5631_PWR_MANAG_ADD3,
1004d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_AXO1MIXER_BIT, 0,
1005d8085222Sjohnnyhsu@realtek.com 			&rt5631_AXO1MIX_mixer_controls[0],
1006d8085222Sjohnnyhsu@realtek.com 			ARRAY_SIZE(rt5631_AXO1MIX_mixer_controls)),
1007d8085222Sjohnnyhsu@realtek.com 	/* SPOL Mixer */
1008d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("SPOLMIX Mixer", SND_SOC_NOPM, 0, 0,
1009d8085222Sjohnnyhsu@realtek.com 			&rt5631_spolmix_mixer_controls[0],
1010d8085222Sjohnnyhsu@realtek.com 			ARRAY_SIZE(rt5631_spolmix_mixer_controls)),
1011d8085222Sjohnnyhsu@realtek.com 	/* MONO Mixer */
1012d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("MONOMIX Mixer", RT5631_PWR_MANAG_ADD3,
1013d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_MONOMIXER_BIT, 0,
1014d8085222Sjohnnyhsu@realtek.com 			&rt5631_monomix_mixer_controls[0],
1015d8085222Sjohnnyhsu@realtek.com 			ARRAY_SIZE(rt5631_monomix_mixer_controls)),
1016d8085222Sjohnnyhsu@realtek.com 	/* SPOR Mixer */
1017d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("SPORMIX Mixer", SND_SOC_NOPM, 0, 0,
1018d8085222Sjohnnyhsu@realtek.com 			&rt5631_spormix_mixer_controls[0],
1019d8085222Sjohnnyhsu@realtek.com 			ARRAY_SIZE(rt5631_spormix_mixer_controls)),
1020d8085222Sjohnnyhsu@realtek.com 	/* AXO2 Mixer */
1021d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MIXER("AXO2MIX Mixer", RT5631_PWR_MANAG_ADD3,
1022d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_AXO2MIXER_BIT, 0,
1023d8085222Sjohnnyhsu@realtek.com 			&rt5631_AXO2MIX_mixer_controls[0],
1024d8085222Sjohnnyhsu@realtek.com 			ARRAY_SIZE(rt5631_AXO2MIX_mixer_controls)),
1025d8085222Sjohnnyhsu@realtek.com 
1026d8085222Sjohnnyhsu@realtek.com 	/* Mux */
1027d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MUX("SPOL Mux", SND_SOC_NOPM, 0, 0,
1028d8085222Sjohnnyhsu@realtek.com 			&rt5631_spol_mux_control),
1029d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MUX("SPOR Mux", SND_SOC_NOPM, 0, 0,
1030d8085222Sjohnnyhsu@realtek.com 			&rt5631_spor_mux_control),
1031d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MUX("MONO Mux", SND_SOC_NOPM, 0, 0,
1032d8085222Sjohnnyhsu@realtek.com 			&rt5631_mono_mux_control),
1033d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MUX("HPL Mux", SND_SOC_NOPM, 0, 0,
1034d8085222Sjohnnyhsu@realtek.com 			&rt5631_hpl_mux_control),
1035d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_MUX("HPR Mux", SND_SOC_NOPM, 0, 0,
1036d8085222Sjohnnyhsu@realtek.com 			&rt5631_hpr_mux_control),
1037d8085222Sjohnnyhsu@realtek.com 
1038d8085222Sjohnnyhsu@realtek.com 	/* AMP supply */
1039d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_SUPPLY("MONO Depop", RT5631_PWR_MANAG_ADD3,
1040d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_MONO_DEPOP_DIS_BIT, 0, NULL, 0),
1041d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_SUPPLY("Class D", RT5631_PWR_MANAG_ADD1,
1042d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_CLASS_D_BIT, 0, NULL, 0),
1043d8085222Sjohnnyhsu@realtek.com 
1044d8085222Sjohnnyhsu@realtek.com 	/* Output Lines */
1045d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_OUTPUT("AUXO1"),
1046d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_OUTPUT("AUXO2"),
1047d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_OUTPUT("SPOL"),
1048d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_OUTPUT("SPOR"),
1049d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_OUTPUT("HPOL"),
1050d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_OUTPUT("HPOR"),
1051d8085222Sjohnnyhsu@realtek.com 	SND_SOC_DAPM_OUTPUT("MONO"),
1052d8085222Sjohnnyhsu@realtek.com };
1053d8085222Sjohnnyhsu@realtek.com 
1054d8085222Sjohnnyhsu@realtek.com static const struct snd_soc_dapm_route rt5631_dapm_routes[] = {
1055d8085222Sjohnnyhsu@realtek.com 	{"MIC1 Boost", NULL, "MIC1"},
1056d8085222Sjohnnyhsu@realtek.com 	{"MIC2 Boost", NULL, "MIC2"},
1057d8085222Sjohnnyhsu@realtek.com 	{"MONOIN_RXP Boost", NULL, "MONOIN_RXP"},
1058d8085222Sjohnnyhsu@realtek.com 	{"MONOIN_RXN Boost", NULL, "MONOIN_RXN"},
1059d8085222Sjohnnyhsu@realtek.com 	{"AXIL Boost", NULL, "AXIL"},
1060d8085222Sjohnnyhsu@realtek.com 	{"AXIR Boost", NULL, "AXIR"},
1061d8085222Sjohnnyhsu@realtek.com 
1062d8085222Sjohnnyhsu@realtek.com 	{"MONO_IN", NULL, "MONOIN_RXP Boost"},
1063d8085222Sjohnnyhsu@realtek.com 	{"MONO_IN", NULL, "MONOIN_RXN Boost"},
1064d8085222Sjohnnyhsu@realtek.com 
1065d8085222Sjohnnyhsu@realtek.com 	{"RECMIXL Mixer", "OUTMIXL Capture Switch", "OUTMIXL Mixer"},
1066d8085222Sjohnnyhsu@realtek.com 	{"RECMIXL Mixer", "MIC1_BST1 Capture Switch", "MIC1 Boost"},
1067d8085222Sjohnnyhsu@realtek.com 	{"RECMIXL Mixer", "AXILVOL Capture Switch", "AXIL Boost"},
1068d8085222Sjohnnyhsu@realtek.com 	{"RECMIXL Mixer", "MONOIN_RX Capture Switch", "MONO_IN"},
1069d8085222Sjohnnyhsu@realtek.com 
1070d8085222Sjohnnyhsu@realtek.com 	{"RECMIXR Mixer", "OUTMIXR Capture Switch", "OUTMIXR Mixer"},
1071d8085222Sjohnnyhsu@realtek.com 	{"RECMIXR Mixer", "MIC2_BST2 Capture Switch", "MIC2 Boost"},
1072d8085222Sjohnnyhsu@realtek.com 	{"RECMIXR Mixer", "AXIRVOL Capture Switch", "AXIR Boost"},
1073d8085222Sjohnnyhsu@realtek.com 	{"RECMIXR Mixer", "MONOIN_RX Capture Switch", "MONO_IN"},
1074d8085222Sjohnnyhsu@realtek.com 
1075d8085222Sjohnnyhsu@realtek.com 	{"ADC Mixer", NULL, "RECMIXL Mixer"},
1076d8085222Sjohnnyhsu@realtek.com 	{"ADC Mixer", NULL, "RECMIXR Mixer"},
1077d8085222Sjohnnyhsu@realtek.com 
1078d8085222Sjohnnyhsu@realtek.com 	{"Left ADC", NULL, "ADC Mixer"},
1079d8085222Sjohnnyhsu@realtek.com 	{"Left ADC", NULL, "Left ADC Select", check_adcl_select},
1080d8085222Sjohnnyhsu@realtek.com 	{"Left ADC", NULL, "PLL1", check_sysclk1_source},
1081d8085222Sjohnnyhsu@realtek.com 	{"Left ADC", NULL, "I2S"},
1082d8085222Sjohnnyhsu@realtek.com 	{"Left ADC", NULL, "DAC REF"},
1083d8085222Sjohnnyhsu@realtek.com 
1084d8085222Sjohnnyhsu@realtek.com 	{"Right ADC", NULL, "ADC Mixer"},
1085d8085222Sjohnnyhsu@realtek.com 	{"Right ADC", NULL, "Right ADC Select", check_adcr_select},
1086d8085222Sjohnnyhsu@realtek.com 	{"Right ADC", NULL, "PLL1", check_sysclk1_source},
1087d8085222Sjohnnyhsu@realtek.com 	{"Right ADC", NULL, "I2S"},
1088d8085222Sjohnnyhsu@realtek.com 	{"Right ADC", NULL, "DAC REF"},
1089d8085222Sjohnnyhsu@realtek.com 
1090d8085222Sjohnnyhsu@realtek.com 	{"DMIC", NULL, "DMIC Supply", check_dmic_used},
1091d8085222Sjohnnyhsu@realtek.com 	{"Left ADC", NULL, "DMIC"},
1092d8085222Sjohnnyhsu@realtek.com 	{"Right ADC", NULL, "DMIC"},
1093d8085222Sjohnnyhsu@realtek.com 
1094d8085222Sjohnnyhsu@realtek.com 	{"Left DAC", NULL, "PLL1", check_sysclk1_source},
1095d8085222Sjohnnyhsu@realtek.com 	{"Left DAC", NULL, "I2S"},
1096d8085222Sjohnnyhsu@realtek.com 	{"Left DAC", NULL, "DAC REF"},
1097d8085222Sjohnnyhsu@realtek.com 	{"Right DAC", NULL, "PLL1", check_sysclk1_source},
1098d8085222Sjohnnyhsu@realtek.com 	{"Right DAC", NULL, "I2S"},
1099d8085222Sjohnnyhsu@realtek.com 	{"Right DAC", NULL, "DAC REF"},
1100d8085222Sjohnnyhsu@realtek.com 
1101d8085222Sjohnnyhsu@realtek.com 	{"Voice DAC Boost", NULL, "Voice DAC"},
1102d8085222Sjohnnyhsu@realtek.com 
1103d8085222Sjohnnyhsu@realtek.com 	{"SPKMIXL Mixer", NULL, "Left DAC To Mixer", check_dacl_to_spkmixl},
1104d8085222Sjohnnyhsu@realtek.com 	{"SPKMIXL Mixer", "RECMIXL Playback Switch", "RECMIXL Mixer"},
1105d8085222Sjohnnyhsu@realtek.com 	{"SPKMIXL Mixer", "MIC1_P Playback Switch", "MIC1"},
1106d8085222Sjohnnyhsu@realtek.com 	{"SPKMIXL Mixer", "DACL Playback Switch", "Left DAC"},
1107d8085222Sjohnnyhsu@realtek.com 	{"SPKMIXL Mixer", "OUTMIXL Playback Switch", "OUTMIXL Mixer"},
1108d8085222Sjohnnyhsu@realtek.com 
1109d8085222Sjohnnyhsu@realtek.com 	{"SPKMIXR Mixer", NULL, "Right DAC To Mixer", check_dacr_to_spkmixr},
1110d8085222Sjohnnyhsu@realtek.com 	{"SPKMIXR Mixer", "OUTMIXR Playback Switch", "OUTMIXR Mixer"},
1111d8085222Sjohnnyhsu@realtek.com 	{"SPKMIXR Mixer", "DACR Playback Switch", "Right DAC"},
1112d8085222Sjohnnyhsu@realtek.com 	{"SPKMIXR Mixer", "MIC2_P Playback Switch", "MIC2"},
1113d8085222Sjohnnyhsu@realtek.com 	{"SPKMIXR Mixer", "RECMIXR Playback Switch", "RECMIXR Mixer"},
1114d8085222Sjohnnyhsu@realtek.com 
1115d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXL Mixer", NULL, "Left DAC To Mixer", check_dacl_to_outmixl},
1116d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXL Mixer", "RECMIXL Playback Switch", "RECMIXL Mixer"},
1117d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXL Mixer", "RECMIXR Playback Switch", "RECMIXR Mixer"},
1118d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXL Mixer", "DACL Playback Switch", "Left DAC"},
1119d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXL Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
1120d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXL Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
1121d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXL Mixer", "MONOIN_RXP Playback Switch", "MONOIN_RXP Boost"},
1122d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXL Mixer", "AXILVOL Playback Switch", "AXIL Boost"},
1123d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXL Mixer", "AXIRVOL Playback Switch", "AXIR Boost"},
1124d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXL Mixer", "VDAC Playback Switch", "Voice DAC Boost"},
1125d8085222Sjohnnyhsu@realtek.com 
1126d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXR Mixer", NULL, "Right DAC To Mixer", check_dacr_to_outmixr},
1127d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXR Mixer", "RECMIXL Playback Switch", "RECMIXL Mixer"},
1128d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXR Mixer", "RECMIXR Playback Switch", "RECMIXR Mixer"},
1129d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXR Mixer", "DACR Playback Switch", "Right DAC"},
1130d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXR Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
1131d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXR Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
1132d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXR Mixer", "MONOIN_RXN Playback Switch", "MONOIN_RXN Boost"},
1133d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXR Mixer", "AXILVOL Playback Switch", "AXIL Boost"},
1134d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXR Mixer", "AXIRVOL Playback Switch", "AXIR Boost"},
1135d8085222Sjohnnyhsu@realtek.com 	{"OUTMIXR Mixer", "VDAC Playback Switch", "Voice DAC Boost"},
1136d8085222Sjohnnyhsu@realtek.com 
1137d8085222Sjohnnyhsu@realtek.com 	{"Left SPKVOL Mux",  "SPKMIXL", "SPKMIXL Mixer"},
1138d8085222Sjohnnyhsu@realtek.com 	{"Left SPKVOL Mux",  "Vmid", "Vmid"},
1139d8085222Sjohnnyhsu@realtek.com 	{"Left HPVOL Mux",  "OUTMIXL", "OUTMIXL Mixer"},
1140d8085222Sjohnnyhsu@realtek.com 	{"Left HPVOL Mux",  "Vmid", "Vmid"},
1141d8085222Sjohnnyhsu@realtek.com 	{"Left OUTVOL Mux",  "OUTMIXL", "OUTMIXL Mixer"},
1142d8085222Sjohnnyhsu@realtek.com 	{"Left OUTVOL Mux",  "Vmid", "Vmid"},
1143d8085222Sjohnnyhsu@realtek.com 	{"Right OUTVOL Mux",  "OUTMIXR", "OUTMIXR Mixer"},
1144d8085222Sjohnnyhsu@realtek.com 	{"Right OUTVOL Mux",  "Vmid", "Vmid"},
1145d8085222Sjohnnyhsu@realtek.com 	{"Right HPVOL Mux",  "OUTMIXR", "OUTMIXR Mixer"},
1146d8085222Sjohnnyhsu@realtek.com 	{"Right HPVOL Mux",  "Vmid", "Vmid"},
1147d8085222Sjohnnyhsu@realtek.com 	{"Right SPKVOL Mux",  "SPKMIXR", "SPKMIXR Mixer"},
1148d8085222Sjohnnyhsu@realtek.com 	{"Right SPKVOL Mux",  "Vmid", "Vmid"},
1149d8085222Sjohnnyhsu@realtek.com 
1150d8085222Sjohnnyhsu@realtek.com 	{"AXO1MIX Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
1151d8085222Sjohnnyhsu@realtek.com 	{"AXO1MIX Mixer", "OUTVOLL Playback Switch", "Left OUTVOL Mux"},
1152d8085222Sjohnnyhsu@realtek.com 	{"AXO1MIX Mixer", "OUTVOLR Playback Switch", "Right OUTVOL Mux"},
1153d8085222Sjohnnyhsu@realtek.com 	{"AXO1MIX Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
1154d8085222Sjohnnyhsu@realtek.com 
1155d8085222Sjohnnyhsu@realtek.com 	{"AXO2MIX Mixer", "MIC1_BST1 Playback Switch", "MIC1 Boost"},
1156d8085222Sjohnnyhsu@realtek.com 	{"AXO2MIX Mixer", "OUTVOLL Playback Switch", "Left OUTVOL Mux"},
1157d8085222Sjohnnyhsu@realtek.com 	{"AXO2MIX Mixer", "OUTVOLR Playback Switch", "Right OUTVOL Mux"},
1158d8085222Sjohnnyhsu@realtek.com 	{"AXO2MIX Mixer", "MIC2_BST2 Playback Switch", "MIC2 Boost"},
1159d8085222Sjohnnyhsu@realtek.com 
1160d8085222Sjohnnyhsu@realtek.com 	{"SPOLMIX Mixer", "SPKVOLL Playback Switch", "Left SPKVOL Mux"},
1161d8085222Sjohnnyhsu@realtek.com 	{"SPOLMIX Mixer", "SPKVOLR Playback Switch", "Right SPKVOL Mux"},
1162d8085222Sjohnnyhsu@realtek.com 
1163d8085222Sjohnnyhsu@realtek.com 	{"SPORMIX Mixer", "SPKVOLL Playback Switch", "Left SPKVOL Mux"},
1164d8085222Sjohnnyhsu@realtek.com 	{"SPORMIX Mixer", "SPKVOLR Playback Switch", "Right SPKVOL Mux"},
1165d8085222Sjohnnyhsu@realtek.com 
1166d8085222Sjohnnyhsu@realtek.com 	{"MONOMIX Mixer", "OUTVOLL Playback Switch", "Left OUTVOL Mux"},
1167d8085222Sjohnnyhsu@realtek.com 	{"MONOMIX Mixer", "OUTVOLR Playback Switch", "Right OUTVOL Mux"},
1168d8085222Sjohnnyhsu@realtek.com 
1169d8085222Sjohnnyhsu@realtek.com 	{"SPOL Mux", "SPOLMIX", "SPOLMIX Mixer"},
1170d8085222Sjohnnyhsu@realtek.com 	{"SPOL Mux", "MONOIN_RX", "MONO_IN"},
1171d8085222Sjohnnyhsu@realtek.com 	{"SPOL Mux", "VDAC", "Voice DAC Boost"},
1172d8085222Sjohnnyhsu@realtek.com 	{"SPOL Mux", "DACL", "Left DAC"},
1173d8085222Sjohnnyhsu@realtek.com 
1174d8085222Sjohnnyhsu@realtek.com 	{"SPOR Mux", "SPORMIX", "SPORMIX Mixer"},
1175d8085222Sjohnnyhsu@realtek.com 	{"SPOR Mux", "MONOIN_RX", "MONO_IN"},
1176d8085222Sjohnnyhsu@realtek.com 	{"SPOR Mux", "VDAC", "Voice DAC Boost"},
1177d8085222Sjohnnyhsu@realtek.com 	{"SPOR Mux", "DACR", "Right DAC"},
1178d8085222Sjohnnyhsu@realtek.com 
1179d8085222Sjohnnyhsu@realtek.com 	{"MONO Mux", "MONOMIX", "MONOMIX Mixer"},
1180d8085222Sjohnnyhsu@realtek.com 	{"MONO Mux", "MONOIN_RX", "MONO_IN"},
1181d8085222Sjohnnyhsu@realtek.com 	{"MONO Mux", "VDAC", "Voice DAC Boost"},
1182d8085222Sjohnnyhsu@realtek.com 
1183d8085222Sjohnnyhsu@realtek.com 	{"Right DAC_HP", NULL, "Right DAC"},
1184d8085222Sjohnnyhsu@realtek.com 	{"Left DAC_HP", NULL, "Left DAC"},
1185d8085222Sjohnnyhsu@realtek.com 
1186d8085222Sjohnnyhsu@realtek.com 	{"HPL Mux", "Left HPVOL", "Left HPVOL Mux"},
1187d8085222Sjohnnyhsu@realtek.com 	{"HPL Mux", "Left DAC", "Left DAC_HP"},
1188d8085222Sjohnnyhsu@realtek.com 	{"HPR Mux", "Right HPVOL", "Right HPVOL Mux"},
1189d8085222Sjohnnyhsu@realtek.com 	{"HPR Mux", "Right DAC", "Right DAC_HP"},
1190d8085222Sjohnnyhsu@realtek.com 
1191d8085222Sjohnnyhsu@realtek.com 	{"HP Depop", NULL, "HPL Mux"},
1192d8085222Sjohnnyhsu@realtek.com 	{"HP Depop", NULL, "HPR Mux"},
1193d8085222Sjohnnyhsu@realtek.com 
1194d8085222Sjohnnyhsu@realtek.com 	{"AUXO1", NULL, "AXO1MIX Mixer"},
1195d8085222Sjohnnyhsu@realtek.com 	{"AUXO2", NULL, "AXO2MIX Mixer"},
1196d8085222Sjohnnyhsu@realtek.com 
1197d8085222Sjohnnyhsu@realtek.com 	{"SPOL", NULL, "Class D"},
1198d8085222Sjohnnyhsu@realtek.com 	{"SPOL", NULL, "SPOL Mux"},
1199d8085222Sjohnnyhsu@realtek.com 	{"SPOR", NULL, "Class D"},
1200d8085222Sjohnnyhsu@realtek.com 	{"SPOR", NULL, "SPOR Mux"},
1201d8085222Sjohnnyhsu@realtek.com 
1202d8085222Sjohnnyhsu@realtek.com 	{"HPOL", NULL, "HP Depop"},
1203d8085222Sjohnnyhsu@realtek.com 	{"HPOR", NULL, "HP Depop"},
1204d8085222Sjohnnyhsu@realtek.com 
1205d8085222Sjohnnyhsu@realtek.com 	{"MONO", NULL, "MONO Depop"},
1206d8085222Sjohnnyhsu@realtek.com 	{"MONO", NULL, "MONO Mux"},
1207d8085222Sjohnnyhsu@realtek.com };
1208d8085222Sjohnnyhsu@realtek.com 
1209d8085222Sjohnnyhsu@realtek.com struct coeff_clk_div {
1210d8085222Sjohnnyhsu@realtek.com 	u32 mclk;
1211d8085222Sjohnnyhsu@realtek.com 	u32 bclk;
1212d8085222Sjohnnyhsu@realtek.com 	u32 rate;
1213d8085222Sjohnnyhsu@realtek.com 	u16 reg_val;
1214d8085222Sjohnnyhsu@realtek.com };
1215d8085222Sjohnnyhsu@realtek.com 
1216d8085222Sjohnnyhsu@realtek.com /* PLL divisors */
1217d8085222Sjohnnyhsu@realtek.com struct pll_div {
1218d8085222Sjohnnyhsu@realtek.com 	u32 pll_in;
1219d8085222Sjohnnyhsu@realtek.com 	u32 pll_out;
1220d8085222Sjohnnyhsu@realtek.com 	u16 reg_val;
1221d8085222Sjohnnyhsu@realtek.com };
1222d8085222Sjohnnyhsu@realtek.com 
1223d8085222Sjohnnyhsu@realtek.com static const struct pll_div codec_master_pll_div[] = {
1224d8085222Sjohnnyhsu@realtek.com 	{2048000,  8192000,  0x0ea0},
1225d8085222Sjohnnyhsu@realtek.com 	{3686400,  8192000,  0x4e27},
1226d8085222Sjohnnyhsu@realtek.com 	{12000000,  8192000,  0x456b},
1227d8085222Sjohnnyhsu@realtek.com 	{13000000,  8192000,  0x495f},
1228d8085222Sjohnnyhsu@realtek.com 	{13100000,  8192000,  0x0320},
1229d8085222Sjohnnyhsu@realtek.com 	{2048000,  11289600,  0xf637},
1230d8085222Sjohnnyhsu@realtek.com 	{3686400,  11289600,  0x2f22},
1231d8085222Sjohnnyhsu@realtek.com 	{12000000,  11289600,  0x3e2f},
1232d8085222Sjohnnyhsu@realtek.com 	{13000000,  11289600,  0x4d5b},
1233d8085222Sjohnnyhsu@realtek.com 	{13100000,  11289600,  0x363b},
1234d8085222Sjohnnyhsu@realtek.com 	{2048000,  16384000,  0x1ea0},
1235d8085222Sjohnnyhsu@realtek.com 	{3686400,  16384000,  0x9e27},
1236d8085222Sjohnnyhsu@realtek.com 	{12000000,  16384000,  0x452b},
1237d8085222Sjohnnyhsu@realtek.com 	{13000000,  16384000,  0x542f},
1238d8085222Sjohnnyhsu@realtek.com 	{13100000,  16384000,  0x03a0},
1239d8085222Sjohnnyhsu@realtek.com 	{2048000,  16934400,  0xe625},
1240d8085222Sjohnnyhsu@realtek.com 	{3686400,  16934400,  0x9126},
1241d8085222Sjohnnyhsu@realtek.com 	{12000000,  16934400,  0x4d2c},
1242d8085222Sjohnnyhsu@realtek.com 	{13000000,  16934400,  0x742f},
1243d8085222Sjohnnyhsu@realtek.com 	{13100000,  16934400,  0x3c27},
1244d8085222Sjohnnyhsu@realtek.com 	{2048000,  22579200,  0x2aa0},
1245d8085222Sjohnnyhsu@realtek.com 	{3686400,  22579200,  0x2f20},
1246d8085222Sjohnnyhsu@realtek.com 	{12000000,  22579200,  0x7e2f},
1247d8085222Sjohnnyhsu@realtek.com 	{13000000,  22579200,  0x742f},
1248d8085222Sjohnnyhsu@realtek.com 	{13100000,  22579200,  0x3c27},
1249d8085222Sjohnnyhsu@realtek.com 	{2048000,  24576000,  0x2ea0},
1250d8085222Sjohnnyhsu@realtek.com 	{3686400,  24576000,  0xee27},
1251d8085222Sjohnnyhsu@realtek.com 	{12000000,  24576000,  0x2915},
1252d8085222Sjohnnyhsu@realtek.com 	{13000000,  24576000,  0x772e},
1253d8085222Sjohnnyhsu@realtek.com 	{13100000,  24576000,  0x0d20},
1254d8085222Sjohnnyhsu@realtek.com 	{26000000,  24576000,  0x2027},
1255d8085222Sjohnnyhsu@realtek.com 	{26000000,  22579200,  0x392f},
1256d8085222Sjohnnyhsu@realtek.com 	{24576000,  22579200,  0x0921},
1257d8085222Sjohnnyhsu@realtek.com 	{24576000,  24576000,  0x02a0},
1258d8085222Sjohnnyhsu@realtek.com };
1259d8085222Sjohnnyhsu@realtek.com 
1260d8085222Sjohnnyhsu@realtek.com static const struct pll_div codec_slave_pll_div[] = {
1261d8085222Sjohnnyhsu@realtek.com 	{256000,  2048000,  0x46f0},
1262d8085222Sjohnnyhsu@realtek.com 	{256000,  4096000,  0x3ea0},
1263d8085222Sjohnnyhsu@realtek.com 	{352800,  5644800,  0x3ea0},
1264d8085222Sjohnnyhsu@realtek.com 	{512000,  8192000,  0x3ea0},
1265d8085222Sjohnnyhsu@realtek.com 	{1024000,  8192000,  0x46f0},
1266d8085222Sjohnnyhsu@realtek.com 	{705600,  11289600,  0x3ea0},
1267d8085222Sjohnnyhsu@realtek.com 	{1024000,  16384000,  0x3ea0},
1268d8085222Sjohnnyhsu@realtek.com 	{1411200,  22579200,  0x3ea0},
1269d8085222Sjohnnyhsu@realtek.com 	{1536000,  24576000,  0x3ea0},
1270d8085222Sjohnnyhsu@realtek.com 	{2048000,  16384000,  0x1ea0},
1271d8085222Sjohnnyhsu@realtek.com 	{2822400,  22579200,  0x1ea0},
1272d8085222Sjohnnyhsu@realtek.com 	{2822400,  45158400,  0x5ec0},
1273d8085222Sjohnnyhsu@realtek.com 	{5644800,  45158400,  0x46f0},
1274d8085222Sjohnnyhsu@realtek.com 	{3072000,  24576000,  0x1ea0},
1275d8085222Sjohnnyhsu@realtek.com 	{3072000,  49152000,  0x5ec0},
1276d8085222Sjohnnyhsu@realtek.com 	{6144000,  49152000,  0x46f0},
1277d8085222Sjohnnyhsu@realtek.com 	{705600,  11289600,  0x3ea0},
1278d8085222Sjohnnyhsu@realtek.com 	{705600,  8467200,  0x3ab0},
1279d8085222Sjohnnyhsu@realtek.com 	{24576000,  24576000,  0x02a0},
1280d8085222Sjohnnyhsu@realtek.com 	{1411200,  11289600,  0x1690},
1281d8085222Sjohnnyhsu@realtek.com 	{2822400,  11289600,  0x0a90},
1282d8085222Sjohnnyhsu@realtek.com 	{1536000,  12288000,  0x1690},
1283d8085222Sjohnnyhsu@realtek.com 	{3072000,  12288000,  0x0a90},
1284d8085222Sjohnnyhsu@realtek.com };
1285d8085222Sjohnnyhsu@realtek.com 
1286c4fd082eSRikard Falkeborn static const struct coeff_clk_div coeff_div[] = {
1287d8085222Sjohnnyhsu@realtek.com 	/* sysclk is 256fs */
1288d8085222Sjohnnyhsu@realtek.com 	{2048000,  8000 * 32,  8000, 0x1000},
1289d8085222Sjohnnyhsu@realtek.com 	{2048000,  8000 * 64,  8000, 0x0000},
1290d8085222Sjohnnyhsu@realtek.com 	{2822400,  11025 * 32,  11025,  0x1000},
1291d8085222Sjohnnyhsu@realtek.com 	{2822400,  11025 * 64,  11025,  0x0000},
1292d8085222Sjohnnyhsu@realtek.com 	{4096000,  16000 * 32,  16000,  0x1000},
1293d8085222Sjohnnyhsu@realtek.com 	{4096000,  16000 * 64,  16000,  0x0000},
1294d8085222Sjohnnyhsu@realtek.com 	{5644800,  22050 * 32,  22050,  0x1000},
1295d8085222Sjohnnyhsu@realtek.com 	{5644800,  22050 * 64,  22050,  0x0000},
1296d8085222Sjohnnyhsu@realtek.com 	{8192000,  32000 * 32,  32000,  0x1000},
1297d8085222Sjohnnyhsu@realtek.com 	{8192000,  32000 * 64,  32000,  0x0000},
1298d8085222Sjohnnyhsu@realtek.com 	{11289600,  44100 * 32,  44100,  0x1000},
1299d8085222Sjohnnyhsu@realtek.com 	{11289600,  44100 * 64,  44100,  0x0000},
1300d8085222Sjohnnyhsu@realtek.com 	{12288000,  48000 * 32,  48000,  0x1000},
1301d8085222Sjohnnyhsu@realtek.com 	{12288000,  48000 * 64,  48000,  0x0000},
1302d8085222Sjohnnyhsu@realtek.com 	{22579200,  88200 * 32,  88200,  0x1000},
1303d8085222Sjohnnyhsu@realtek.com 	{22579200,  88200 * 64,  88200,  0x0000},
1304d8085222Sjohnnyhsu@realtek.com 	{24576000,  96000 * 32,  96000,  0x1000},
1305d8085222Sjohnnyhsu@realtek.com 	{24576000,  96000 * 64,  96000,  0x0000},
1306d8085222Sjohnnyhsu@realtek.com 	/* sysclk is 512fs */
1307d8085222Sjohnnyhsu@realtek.com 	{4096000,  8000 * 32,  8000, 0x3000},
1308d8085222Sjohnnyhsu@realtek.com 	{4096000,  8000 * 64,  8000, 0x2000},
1309d8085222Sjohnnyhsu@realtek.com 	{5644800,  11025 * 32,  11025, 0x3000},
1310d8085222Sjohnnyhsu@realtek.com 	{5644800,  11025 * 64,  11025, 0x2000},
1311d8085222Sjohnnyhsu@realtek.com 	{8192000,  16000 * 32,  16000, 0x3000},
1312d8085222Sjohnnyhsu@realtek.com 	{8192000,  16000 * 64,  16000, 0x2000},
1313d8085222Sjohnnyhsu@realtek.com 	{11289600,  22050 * 32,  22050, 0x3000},
1314d8085222Sjohnnyhsu@realtek.com 	{11289600,  22050 * 64,  22050, 0x2000},
1315d8085222Sjohnnyhsu@realtek.com 	{16384000,  32000 * 32,  32000, 0x3000},
1316d8085222Sjohnnyhsu@realtek.com 	{16384000,  32000 * 64,  32000, 0x2000},
1317d8085222Sjohnnyhsu@realtek.com 	{22579200,  44100 * 32,  44100, 0x3000},
1318d8085222Sjohnnyhsu@realtek.com 	{22579200,  44100 * 64,  44100, 0x2000},
1319d8085222Sjohnnyhsu@realtek.com 	{24576000,  48000 * 32,  48000, 0x3000},
1320d8085222Sjohnnyhsu@realtek.com 	{24576000,  48000 * 64,  48000, 0x2000},
1321d8085222Sjohnnyhsu@realtek.com 	{45158400,  88200 * 32,  88200, 0x3000},
1322d8085222Sjohnnyhsu@realtek.com 	{45158400,  88200 * 64,  88200, 0x2000},
1323d8085222Sjohnnyhsu@realtek.com 	{49152000,  96000 * 32,  96000, 0x3000},
1324d8085222Sjohnnyhsu@realtek.com 	{49152000,  96000 * 64,  96000, 0x2000},
1325d8085222Sjohnnyhsu@realtek.com 	/* sysclk is 24.576Mhz or 22.5792Mhz */
1326d8085222Sjohnnyhsu@realtek.com 	{24576000,  8000 * 32,  8000,  0x7080},
1327d8085222Sjohnnyhsu@realtek.com 	{24576000,  8000 * 64,  8000,  0x6080},
1328d8085222Sjohnnyhsu@realtek.com 	{24576000,  16000 * 32,  16000,  0x5080},
1329d8085222Sjohnnyhsu@realtek.com 	{24576000,  16000 * 64,  16000,  0x4080},
1330d8085222Sjohnnyhsu@realtek.com 	{24576000,  24000 * 32,  24000,  0x5000},
1331d8085222Sjohnnyhsu@realtek.com 	{24576000,  24000 * 64,  24000,  0x4000},
1332d8085222Sjohnnyhsu@realtek.com 	{24576000,  32000 * 32,  32000,  0x3080},
1333d8085222Sjohnnyhsu@realtek.com 	{24576000,  32000 * 64,  32000,  0x2080},
1334d8085222Sjohnnyhsu@realtek.com 	{22579200,  11025 * 32,  11025,  0x7000},
1335d8085222Sjohnnyhsu@realtek.com 	{22579200,  11025 * 64,  11025,  0x6000},
1336d8085222Sjohnnyhsu@realtek.com 	{22579200,  22050 * 32,  22050,  0x5000},
1337d8085222Sjohnnyhsu@realtek.com 	{22579200,  22050 * 64,  22050,  0x4000},
1338d8085222Sjohnnyhsu@realtek.com };
1339d8085222Sjohnnyhsu@realtek.com 
get_coeff(int mclk,int rate,int timesofbclk)1340d8085222Sjohnnyhsu@realtek.com static int get_coeff(int mclk, int rate, int timesofbclk)
1341d8085222Sjohnnyhsu@realtek.com {
1342d8085222Sjohnnyhsu@realtek.com 	int i;
1343d8085222Sjohnnyhsu@realtek.com 
1344d8085222Sjohnnyhsu@realtek.com 	for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
1345d8085222Sjohnnyhsu@realtek.com 		if (coeff_div[i].mclk == mclk && coeff_div[i].rate == rate &&
1346d8085222Sjohnnyhsu@realtek.com 			(coeff_div[i].bclk / coeff_div[i].rate) == timesofbclk)
1347d8085222Sjohnnyhsu@realtek.com 			return i;
1348d8085222Sjohnnyhsu@realtek.com 	}
1349d8085222Sjohnnyhsu@realtek.com 	return -EINVAL;
1350d8085222Sjohnnyhsu@realtek.com }
1351d8085222Sjohnnyhsu@realtek.com 
rt5631_hifi_pcm_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)1352d8085222Sjohnnyhsu@realtek.com static int rt5631_hifi_pcm_params(struct snd_pcm_substream *substream,
1353d8085222Sjohnnyhsu@realtek.com 		struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
1354d8085222Sjohnnyhsu@realtek.com {
135546295e5eSKuninori Morimoto 	struct snd_soc_component *component = dai->component;
135646295e5eSKuninori Morimoto 	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
1357d8085222Sjohnnyhsu@realtek.com 	int timesofbclk = 32, coeff;
1358d8085222Sjohnnyhsu@realtek.com 	unsigned int iface = 0;
1359d8085222Sjohnnyhsu@realtek.com 
136046295e5eSKuninori Morimoto 	dev_dbg(component->dev, "enter %s\n", __func__);
1361d8085222Sjohnnyhsu@realtek.com 
1362d8085222Sjohnnyhsu@realtek.com 	rt5631->bclk_rate = snd_soc_params_to_bclk(params);
1363d8085222Sjohnnyhsu@realtek.com 	if (rt5631->bclk_rate < 0) {
136446295e5eSKuninori Morimoto 		dev_err(component->dev, "Fail to get BCLK rate\n");
1365d8085222Sjohnnyhsu@realtek.com 		return rt5631->bclk_rate;
1366d8085222Sjohnnyhsu@realtek.com 	}
1367d8085222Sjohnnyhsu@realtek.com 	rt5631->rx_rate = params_rate(params);
1368d8085222Sjohnnyhsu@realtek.com 
1369d8085222Sjohnnyhsu@realtek.com 	if (rt5631->master)
1370d8085222Sjohnnyhsu@realtek.com 		coeff = get_coeff(rt5631->sysclk, rt5631->rx_rate,
1371d8085222Sjohnnyhsu@realtek.com 			rt5631->bclk_rate / rt5631->rx_rate);
1372d8085222Sjohnnyhsu@realtek.com 	else
1373d8085222Sjohnnyhsu@realtek.com 		coeff = get_coeff(rt5631->sysclk, rt5631->rx_rate,
1374d8085222Sjohnnyhsu@realtek.com 					timesofbclk);
1375d8085222Sjohnnyhsu@realtek.com 	if (coeff < 0) {
137646295e5eSKuninori Morimoto 		dev_err(component->dev, "Fail to get coeff\n");
13772525808eSSachin Kamat 		return coeff;
1378d8085222Sjohnnyhsu@realtek.com 	}
1379d8085222Sjohnnyhsu@realtek.com 
1380e6777eadSMark Brown 	switch (params_width(params)) {
1381e6777eadSMark Brown 	case 16:
1382d8085222Sjohnnyhsu@realtek.com 		break;
1383e6777eadSMark Brown 	case 20:
1384d8085222Sjohnnyhsu@realtek.com 		iface |= RT5631_SDP_I2S_DL_20;
1385d8085222Sjohnnyhsu@realtek.com 		break;
1386e6777eadSMark Brown 	case 24:
1387d8085222Sjohnnyhsu@realtek.com 		iface |= RT5631_SDP_I2S_DL_24;
1388d8085222Sjohnnyhsu@realtek.com 		break;
1389e6777eadSMark Brown 	case 8:
1390d8085222Sjohnnyhsu@realtek.com 		iface |= RT5631_SDP_I2S_DL_8;
1391d8085222Sjohnnyhsu@realtek.com 		break;
1392d8085222Sjohnnyhsu@realtek.com 	default:
1393d8085222Sjohnnyhsu@realtek.com 		return -EINVAL;
1394d8085222Sjohnnyhsu@realtek.com 	}
1395d8085222Sjohnnyhsu@realtek.com 
139646295e5eSKuninori Morimoto 	snd_soc_component_update_bits(component, RT5631_SDP_CTRL,
1397d8085222Sjohnnyhsu@realtek.com 		RT5631_SDP_I2S_DL_MASK, iface);
139846295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_STEREO_AD_DA_CLK_CTRL,
1399d8085222Sjohnnyhsu@realtek.com 					coeff_div[coeff].reg_val);
1400d8085222Sjohnnyhsu@realtek.com 
1401d8085222Sjohnnyhsu@realtek.com 	return 0;
1402d8085222Sjohnnyhsu@realtek.com }
1403d8085222Sjohnnyhsu@realtek.com 
rt5631_hifi_codec_set_dai_fmt(struct snd_soc_dai * codec_dai,unsigned int fmt)1404d8085222Sjohnnyhsu@realtek.com static int rt5631_hifi_codec_set_dai_fmt(struct snd_soc_dai *codec_dai,
1405d8085222Sjohnnyhsu@realtek.com 						unsigned int fmt)
1406d8085222Sjohnnyhsu@realtek.com {
140746295e5eSKuninori Morimoto 	struct snd_soc_component *component = codec_dai->component;
140846295e5eSKuninori Morimoto 	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
1409d8085222Sjohnnyhsu@realtek.com 	unsigned int iface = 0;
1410d8085222Sjohnnyhsu@realtek.com 
141146295e5eSKuninori Morimoto 	dev_dbg(component->dev, "enter %s\n", __func__);
1412d8085222Sjohnnyhsu@realtek.com 
1413d8085222Sjohnnyhsu@realtek.com 	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1414d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_DAIFMT_CBM_CFM:
1415d8085222Sjohnnyhsu@realtek.com 		rt5631->master = 1;
1416d8085222Sjohnnyhsu@realtek.com 		break;
1417d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_DAIFMT_CBS_CFS:
1418d8085222Sjohnnyhsu@realtek.com 		iface |= RT5631_SDP_MODE_SEL_SLAVE;
1419d8085222Sjohnnyhsu@realtek.com 		rt5631->master = 0;
1420d8085222Sjohnnyhsu@realtek.com 		break;
1421d8085222Sjohnnyhsu@realtek.com 	default:
1422d8085222Sjohnnyhsu@realtek.com 		return -EINVAL;
1423d8085222Sjohnnyhsu@realtek.com 	}
1424d8085222Sjohnnyhsu@realtek.com 
1425d8085222Sjohnnyhsu@realtek.com 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1426d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_DAIFMT_I2S:
1427d8085222Sjohnnyhsu@realtek.com 		break;
1428d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_DAIFMT_LEFT_J:
1429d8085222Sjohnnyhsu@realtek.com 		iface |= RT5631_SDP_I2S_DF_LEFT;
1430d8085222Sjohnnyhsu@realtek.com 		break;
1431d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_DAIFMT_DSP_A:
1432d8085222Sjohnnyhsu@realtek.com 		iface |= RT5631_SDP_I2S_DF_PCM_A;
1433d8085222Sjohnnyhsu@realtek.com 		break;
1434d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_DAIFMT_DSP_B:
1435d8085222Sjohnnyhsu@realtek.com 		iface  |= RT5631_SDP_I2S_DF_PCM_B;
1436d8085222Sjohnnyhsu@realtek.com 		break;
1437d8085222Sjohnnyhsu@realtek.com 	default:
1438d8085222Sjohnnyhsu@realtek.com 		return -EINVAL;
1439d8085222Sjohnnyhsu@realtek.com 	}
1440d8085222Sjohnnyhsu@realtek.com 
1441d8085222Sjohnnyhsu@realtek.com 	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1442d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_DAIFMT_NB_NF:
1443d8085222Sjohnnyhsu@realtek.com 		break;
1444d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_DAIFMT_IB_NF:
1445d8085222Sjohnnyhsu@realtek.com 		iface |= RT5631_SDP_I2S_BCLK_POL_CTRL;
1446d8085222Sjohnnyhsu@realtek.com 		break;
1447d8085222Sjohnnyhsu@realtek.com 	default:
1448d8085222Sjohnnyhsu@realtek.com 		return -EINVAL;
1449d8085222Sjohnnyhsu@realtek.com 	}
1450d8085222Sjohnnyhsu@realtek.com 
145146295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_SDP_CTRL, iface);
1452d8085222Sjohnnyhsu@realtek.com 
1453d8085222Sjohnnyhsu@realtek.com 	return 0;
1454d8085222Sjohnnyhsu@realtek.com }
1455d8085222Sjohnnyhsu@realtek.com 
rt5631_hifi_codec_set_dai_sysclk(struct snd_soc_dai * codec_dai,int clk_id,unsigned int freq,int dir)1456d8085222Sjohnnyhsu@realtek.com static int rt5631_hifi_codec_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1457d8085222Sjohnnyhsu@realtek.com 				int clk_id, unsigned int freq, int dir)
1458d8085222Sjohnnyhsu@realtek.com {
145946295e5eSKuninori Morimoto 	struct snd_soc_component *component = codec_dai->component;
146046295e5eSKuninori Morimoto 	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
1461d8085222Sjohnnyhsu@realtek.com 
146246295e5eSKuninori Morimoto 	dev_dbg(component->dev, "enter %s, syclk=%d\n", __func__, freq);
1463d8085222Sjohnnyhsu@realtek.com 
1464d8085222Sjohnnyhsu@realtek.com 	if ((freq >= (256 * 8000)) && (freq <= (512 * 96000))) {
1465d8085222Sjohnnyhsu@realtek.com 		rt5631->sysclk = freq;
1466d8085222Sjohnnyhsu@realtek.com 		return 0;
1467d8085222Sjohnnyhsu@realtek.com 	}
1468d8085222Sjohnnyhsu@realtek.com 
1469d8085222Sjohnnyhsu@realtek.com 	return -EINVAL;
1470d8085222Sjohnnyhsu@realtek.com }
1471d8085222Sjohnnyhsu@realtek.com 
rt5631_codec_set_dai_pll(struct snd_soc_dai * codec_dai,int pll_id,int source,unsigned int freq_in,unsigned int freq_out)1472d8085222Sjohnnyhsu@realtek.com static int rt5631_codec_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
1473d8085222Sjohnnyhsu@realtek.com 		int source, unsigned int freq_in, unsigned int freq_out)
1474d8085222Sjohnnyhsu@realtek.com {
147546295e5eSKuninori Morimoto 	struct snd_soc_component *component = codec_dai->component;
147646295e5eSKuninori Morimoto 	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
1477d8085222Sjohnnyhsu@realtek.com 	int i, ret = -EINVAL;
1478d8085222Sjohnnyhsu@realtek.com 
147946295e5eSKuninori Morimoto 	dev_dbg(component->dev, "enter %s\n", __func__);
1480d8085222Sjohnnyhsu@realtek.com 
1481d8085222Sjohnnyhsu@realtek.com 	if (!freq_in || !freq_out) {
148246295e5eSKuninori Morimoto 		dev_dbg(component->dev, "PLL disabled\n");
1483d8085222Sjohnnyhsu@realtek.com 
148446295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_GLOBAL_CLK_CTRL,
1485d8085222Sjohnnyhsu@realtek.com 			RT5631_SYSCLK_SOUR_SEL_MASK,
1486d8085222Sjohnnyhsu@realtek.com 			RT5631_SYSCLK_SOUR_SEL_MCLK);
1487d8085222Sjohnnyhsu@realtek.com 
1488d8085222Sjohnnyhsu@realtek.com 		return 0;
1489d8085222Sjohnnyhsu@realtek.com 	}
1490d8085222Sjohnnyhsu@realtek.com 
1491d8085222Sjohnnyhsu@realtek.com 	if (rt5631->master) {
1492d8085222Sjohnnyhsu@realtek.com 		for (i = 0; i < ARRAY_SIZE(codec_master_pll_div); i++)
1493d8085222Sjohnnyhsu@realtek.com 			if (freq_in == codec_master_pll_div[i].pll_in &&
1494d8085222Sjohnnyhsu@realtek.com 			freq_out == codec_master_pll_div[i].pll_out) {
149546295e5eSKuninori Morimoto 				dev_info(component->dev,
1496d8085222Sjohnnyhsu@realtek.com 					"change PLL in master mode\n");
149746295e5eSKuninori Morimoto 				snd_soc_component_write(component, RT5631_PLL_CTRL,
1498d8085222Sjohnnyhsu@realtek.com 					codec_master_pll_div[i].reg_val);
1499d8085222Sjohnnyhsu@realtek.com 				schedule_timeout_uninterruptible(
1500d8085222Sjohnnyhsu@realtek.com 					msecs_to_jiffies(20));
150146295e5eSKuninori Morimoto 				snd_soc_component_update_bits(component,
1502d8085222Sjohnnyhsu@realtek.com 					RT5631_GLOBAL_CLK_CTRL,
1503d8085222Sjohnnyhsu@realtek.com 					RT5631_SYSCLK_SOUR_SEL_MASK |
1504d8085222Sjohnnyhsu@realtek.com 					RT5631_PLLCLK_SOUR_SEL_MASK,
1505d8085222Sjohnnyhsu@realtek.com 					RT5631_SYSCLK_SOUR_SEL_PLL |
1506d8085222Sjohnnyhsu@realtek.com 					RT5631_PLLCLK_SOUR_SEL_MCLK);
1507d8085222Sjohnnyhsu@realtek.com 				ret = 0;
1508d8085222Sjohnnyhsu@realtek.com 				break;
1509d8085222Sjohnnyhsu@realtek.com 			}
1510d8085222Sjohnnyhsu@realtek.com 	} else {
1511d8085222Sjohnnyhsu@realtek.com 		for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++)
1512d8085222Sjohnnyhsu@realtek.com 			if (freq_in == codec_slave_pll_div[i].pll_in &&
1513d8085222Sjohnnyhsu@realtek.com 			freq_out == codec_slave_pll_div[i].pll_out) {
151446295e5eSKuninori Morimoto 				dev_info(component->dev,
1515d8085222Sjohnnyhsu@realtek.com 					"change PLL in slave mode\n");
151646295e5eSKuninori Morimoto 				snd_soc_component_write(component, RT5631_PLL_CTRL,
1517d8085222Sjohnnyhsu@realtek.com 					codec_slave_pll_div[i].reg_val);
1518d8085222Sjohnnyhsu@realtek.com 				schedule_timeout_uninterruptible(
1519d8085222Sjohnnyhsu@realtek.com 					msecs_to_jiffies(20));
152046295e5eSKuninori Morimoto 				snd_soc_component_update_bits(component,
1521d8085222Sjohnnyhsu@realtek.com 					RT5631_GLOBAL_CLK_CTRL,
1522d8085222Sjohnnyhsu@realtek.com 					RT5631_SYSCLK_SOUR_SEL_MASK |
1523d8085222Sjohnnyhsu@realtek.com 					RT5631_PLLCLK_SOUR_SEL_MASK,
1524d8085222Sjohnnyhsu@realtek.com 					RT5631_SYSCLK_SOUR_SEL_PLL |
1525d8085222Sjohnnyhsu@realtek.com 					RT5631_PLLCLK_SOUR_SEL_BCLK);
1526d8085222Sjohnnyhsu@realtek.com 				ret = 0;
1527d8085222Sjohnnyhsu@realtek.com 				break;
1528d8085222Sjohnnyhsu@realtek.com 			}
1529d8085222Sjohnnyhsu@realtek.com 	}
1530d8085222Sjohnnyhsu@realtek.com 
1531d8085222Sjohnnyhsu@realtek.com 	return ret;
1532d8085222Sjohnnyhsu@realtek.com }
1533d8085222Sjohnnyhsu@realtek.com 
rt5631_set_bias_level(struct snd_soc_component * component,enum snd_soc_bias_level level)153446295e5eSKuninori Morimoto static int rt5631_set_bias_level(struct snd_soc_component *component,
1535d8085222Sjohnnyhsu@realtek.com 			enum snd_soc_bias_level level)
1536d8085222Sjohnnyhsu@realtek.com {
153746295e5eSKuninori Morimoto 	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
153801476801SMark Brown 
1539d8085222Sjohnnyhsu@realtek.com 	switch (level) {
1540d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_BIAS_ON:
1541d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_BIAS_PREPARE:
154246295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD2,
1543d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_MICBIAS1_VOL | RT5631_PWR_MICBIAS2_VOL,
1544d8085222Sjohnnyhsu@realtek.com 			RT5631_PWR_MICBIAS1_VOL | RT5631_PWR_MICBIAS2_VOL);
1545d8085222Sjohnnyhsu@realtek.com 		break;
1546d8085222Sjohnnyhsu@realtek.com 
1547d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_BIAS_STANDBY:
154846295e5eSKuninori Morimoto 		if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
154946295e5eSKuninori Morimoto 			snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
1550d8085222Sjohnnyhsu@realtek.com 				RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS,
1551d8085222Sjohnnyhsu@realtek.com 				RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS);
1552d8085222Sjohnnyhsu@realtek.com 			msleep(80);
155346295e5eSKuninori Morimoto 			snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
1554d8085222Sjohnnyhsu@realtek.com 				RT5631_PWR_FAST_VREF_CTRL,
1555d8085222Sjohnnyhsu@realtek.com 				RT5631_PWR_FAST_VREF_CTRL);
155601476801SMark Brown 			regcache_cache_only(rt5631->regmap, false);
155701476801SMark Brown 			regcache_sync(rt5631->regmap);
1558d8085222Sjohnnyhsu@realtek.com 		}
1559d8085222Sjohnnyhsu@realtek.com 		break;
1560d8085222Sjohnnyhsu@realtek.com 
1561d8085222Sjohnnyhsu@realtek.com 	case SND_SOC_BIAS_OFF:
156246295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_PWR_MANAG_ADD1, 0x0000);
156346295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_PWR_MANAG_ADD2, 0x0000);
156446295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_PWR_MANAG_ADD3, 0x0000);
156546295e5eSKuninori Morimoto 		snd_soc_component_write(component, RT5631_PWR_MANAG_ADD4, 0x0000);
1566d8085222Sjohnnyhsu@realtek.com 		break;
1567d8085222Sjohnnyhsu@realtek.com 
1568d8085222Sjohnnyhsu@realtek.com 	default:
1569d8085222Sjohnnyhsu@realtek.com 		break;
1570d8085222Sjohnnyhsu@realtek.com 	}
1571d8085222Sjohnnyhsu@realtek.com 
1572d8085222Sjohnnyhsu@realtek.com 	return 0;
1573d8085222Sjohnnyhsu@realtek.com }
1574d8085222Sjohnnyhsu@realtek.com 
rt5631_probe(struct snd_soc_component * component)157546295e5eSKuninori Morimoto static int rt5631_probe(struct snd_soc_component *component)
1576d8085222Sjohnnyhsu@realtek.com {
157746295e5eSKuninori Morimoto 	struct rt5631_priv *rt5631 = snd_soc_component_get_drvdata(component);
1578d8085222Sjohnnyhsu@realtek.com 	unsigned int val;
1579d8085222Sjohnnyhsu@realtek.com 
158046295e5eSKuninori Morimoto 	val = rt5631_read_index(component, RT5631_ADDA_MIXER_INTL_REG3);
1581d8085222Sjohnnyhsu@realtek.com 	if (val & 0x0002)
1582d8085222Sjohnnyhsu@realtek.com 		rt5631->codec_version = 1;
1583d8085222Sjohnnyhsu@realtek.com 	else
1584d8085222Sjohnnyhsu@realtek.com 		rt5631->codec_version = 0;
1585d8085222Sjohnnyhsu@realtek.com 
158646295e5eSKuninori Morimoto 	rt5631_reset(component);
158746295e5eSKuninori Morimoto 	snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
1588d8085222Sjohnnyhsu@realtek.com 		RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS,
1589d8085222Sjohnnyhsu@realtek.com 		RT5631_PWR_VREF | RT5631_PWR_MAIN_BIAS);
1590d8085222Sjohnnyhsu@realtek.com 	msleep(80);
159146295e5eSKuninori Morimoto 	snd_soc_component_update_bits(component, RT5631_PWR_MANAG_ADD3,
1592d8085222Sjohnnyhsu@realtek.com 		RT5631_PWR_FAST_VREF_CTRL, RT5631_PWR_FAST_VREF_CTRL);
1593d8085222Sjohnnyhsu@realtek.com 	/* enable HP zero cross */
159446295e5eSKuninori Morimoto 	snd_soc_component_write(component, RT5631_INT_ST_IRQ_CTRL_2, 0x0f18);
1595d8085222Sjohnnyhsu@realtek.com 	/* power off ClassD auto Recovery */
1596d8085222Sjohnnyhsu@realtek.com 	if (rt5631->codec_version)
159746295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_INT_ST_IRQ_CTRL_2,
1598d8085222Sjohnnyhsu@realtek.com 					0x2000, 0x2000);
1599d8085222Sjohnnyhsu@realtek.com 	else
160046295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_INT_ST_IRQ_CTRL_2,
1601d8085222Sjohnnyhsu@realtek.com 					0x2000, 0);
1602d8085222Sjohnnyhsu@realtek.com 	/* DMIC */
1603d8085222Sjohnnyhsu@realtek.com 	if (rt5631->dmic_used_flag) {
160446295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_GPIO_CTRL,
1605d8085222Sjohnnyhsu@realtek.com 			RT5631_GPIO_PIN_FUN_SEL_MASK |
1606d8085222Sjohnnyhsu@realtek.com 			RT5631_GPIO_DMIC_FUN_SEL_MASK,
1607d8085222Sjohnnyhsu@realtek.com 			RT5631_GPIO_PIN_FUN_SEL_GPIO_DIMC |
1608d8085222Sjohnnyhsu@realtek.com 			RT5631_GPIO_DMIC_FUN_SEL_DIMC);
160946295e5eSKuninori Morimoto 		snd_soc_component_update_bits(component, RT5631_DIG_MIC_CTRL,
1610d8085222Sjohnnyhsu@realtek.com 			RT5631_DMIC_L_CH_LATCH_MASK |
1611d8085222Sjohnnyhsu@realtek.com 			RT5631_DMIC_R_CH_LATCH_MASK,
1612d8085222Sjohnnyhsu@realtek.com 			RT5631_DMIC_L_CH_LATCH_FALLING |
1613d8085222Sjohnnyhsu@realtek.com 			RT5631_DMIC_R_CH_LATCH_RISING);
1614d8085222Sjohnnyhsu@realtek.com 	}
1615d8085222Sjohnnyhsu@realtek.com 
161646295e5eSKuninori Morimoto 	snd_soc_component_init_bias_level(component, SND_SOC_BIAS_STANDBY);
1617d8085222Sjohnnyhsu@realtek.com 
1618d8085222Sjohnnyhsu@realtek.com 	return 0;
1619d8085222Sjohnnyhsu@realtek.com }
1620d8085222Sjohnnyhsu@realtek.com 
1621d8085222Sjohnnyhsu@realtek.com #define RT5631_STEREO_RATES SNDRV_PCM_RATE_8000_96000
1622d8085222Sjohnnyhsu@realtek.com #define RT5631_FORMAT	(SNDRV_PCM_FMTBIT_S16_LE | \
1623d8085222Sjohnnyhsu@realtek.com 			SNDRV_PCM_FMTBIT_S20_3LE | \
1624d8085222Sjohnnyhsu@realtek.com 			SNDRV_PCM_FMTBIT_S24_LE | \
1625d8085222Sjohnnyhsu@realtek.com 			SNDRV_PCM_FMTBIT_S8)
1626d8085222Sjohnnyhsu@realtek.com 
162785e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops rt5631_ops = {
1628d8085222Sjohnnyhsu@realtek.com 	.hw_params = rt5631_hifi_pcm_params,
1629d8085222Sjohnnyhsu@realtek.com 	.set_fmt = rt5631_hifi_codec_set_dai_fmt,
1630d8085222Sjohnnyhsu@realtek.com 	.set_sysclk = rt5631_hifi_codec_set_dai_sysclk,
1631d8085222Sjohnnyhsu@realtek.com 	.set_pll = rt5631_codec_set_dai_pll,
1632d8085222Sjohnnyhsu@realtek.com };
1633d8085222Sjohnnyhsu@realtek.com 
163451e19fb3SAxel Lin static struct snd_soc_dai_driver rt5631_dai[] = {
1635d8085222Sjohnnyhsu@realtek.com 	{
1636d8085222Sjohnnyhsu@realtek.com 		.name = "rt5631-hifi",
1637d8085222Sjohnnyhsu@realtek.com 		.id = 1,
1638d8085222Sjohnnyhsu@realtek.com 		.playback = {
1639d8085222Sjohnnyhsu@realtek.com 			.stream_name = "HIFI Playback",
1640d8085222Sjohnnyhsu@realtek.com 			.channels_min = 1,
1641d8085222Sjohnnyhsu@realtek.com 			.channels_max = 2,
1642d8085222Sjohnnyhsu@realtek.com 			.rates = RT5631_STEREO_RATES,
1643d8085222Sjohnnyhsu@realtek.com 			.formats = RT5631_FORMAT,
1644d8085222Sjohnnyhsu@realtek.com 		},
1645d8085222Sjohnnyhsu@realtek.com 		.capture = {
1646d8085222Sjohnnyhsu@realtek.com 			.stream_name = "HIFI Capture",
1647d8085222Sjohnnyhsu@realtek.com 			.channels_min = 1,
1648d8085222Sjohnnyhsu@realtek.com 			.channels_max = 2,
1649d8085222Sjohnnyhsu@realtek.com 			.rates = RT5631_STEREO_RATES,
1650d8085222Sjohnnyhsu@realtek.com 			.formats = RT5631_FORMAT,
1651d8085222Sjohnnyhsu@realtek.com 		},
1652d8085222Sjohnnyhsu@realtek.com 		.ops = &rt5631_ops,
1653d8085222Sjohnnyhsu@realtek.com 	},
1654d8085222Sjohnnyhsu@realtek.com };
1655d8085222Sjohnnyhsu@realtek.com 
165646295e5eSKuninori Morimoto static const struct snd_soc_component_driver soc_component_dev_rt5631 = {
1657d8085222Sjohnnyhsu@realtek.com 	.probe			= rt5631_probe,
1658d8085222Sjohnnyhsu@realtek.com 	.set_bias_level		= rt5631_set_bias_level,
1659d8085222Sjohnnyhsu@realtek.com 	.controls		= rt5631_snd_controls,
1660d8085222Sjohnnyhsu@realtek.com 	.num_controls		= ARRAY_SIZE(rt5631_snd_controls),
1661d8085222Sjohnnyhsu@realtek.com 	.dapm_widgets		= rt5631_dapm_widgets,
1662d8085222Sjohnnyhsu@realtek.com 	.num_dapm_widgets	= ARRAY_SIZE(rt5631_dapm_widgets),
1663d8085222Sjohnnyhsu@realtek.com 	.dapm_routes		= rt5631_dapm_routes,
1664d8085222Sjohnnyhsu@realtek.com 	.num_dapm_routes	= ARRAY_SIZE(rt5631_dapm_routes),
166546295e5eSKuninori Morimoto 	.suspend_bias_off	= 1,
166646295e5eSKuninori Morimoto 	.idle_bias_on		= 1,
166746295e5eSKuninori Morimoto 	.use_pmdown_time	= 1,
166846295e5eSKuninori Morimoto 	.endianness		= 1,
1669d8085222Sjohnnyhsu@realtek.com };
1670d8085222Sjohnnyhsu@realtek.com 
1671d8085222Sjohnnyhsu@realtek.com static const struct i2c_device_id rt5631_i2c_id[] = {
1672d8085222Sjohnnyhsu@realtek.com 	{ "rt5631", 0 },
1673189c88ceSKrishna Mohan Dani 	{ "alc5631", 0 },
1674d8085222Sjohnnyhsu@realtek.com 	{ }
1675d8085222Sjohnnyhsu@realtek.com };
1676d8085222Sjohnnyhsu@realtek.com MODULE_DEVICE_TABLE(i2c, rt5631_i2c_id);
1677d8085222Sjohnnyhsu@realtek.com 
1678187024b3SKrishna Mohan Dani #ifdef CONFIG_OF
1679261e43a3SFabian Frederick static const struct of_device_id rt5631_i2c_dt_ids[] = {
1680189c88ceSKrishna Mohan Dani 	{ .compatible = "realtek,rt5631"},
1681189c88ceSKrishna Mohan Dani 	{ .compatible = "realtek,alc5631"},
1682189c88ceSKrishna Mohan Dani 	{ }
1683189c88ceSKrishna Mohan Dani };
1684189c88ceSKrishna Mohan Dani MODULE_DEVICE_TABLE(of, rt5631_i2c_dt_ids);
1685187024b3SKrishna Mohan Dani #endif
1686189c88ceSKrishna Mohan Dani 
168701476801SMark Brown static const struct regmap_config rt5631_regmap_config = {
168801476801SMark Brown 	.reg_bits = 8,
168901476801SMark Brown 	.val_bits = 16,
169001476801SMark Brown 
169101476801SMark Brown 	.readable_reg = rt5631_readable_register,
169201476801SMark Brown 	.volatile_reg = rt5631_volatile_register,
169301476801SMark Brown 	.max_register = RT5631_VENDOR_ID2,
169401476801SMark Brown 	.reg_defaults = rt5631_reg,
169501476801SMark Brown 	.num_reg_defaults = ARRAY_SIZE(rt5631_reg),
1696*8a738490SMark Brown 	.cache_type = REGCACHE_MAPLE,
1697c71f78a6SMaxim Schwalm 	.use_single_read = true,
1698c71f78a6SMaxim Schwalm 	.use_single_write = true,
169901476801SMark Brown };
170001476801SMark Brown 
rt5631_i2c_probe(struct i2c_client * i2c)170135b88858SStephen Kitt static int rt5631_i2c_probe(struct i2c_client *i2c)
1702d8085222Sjohnnyhsu@realtek.com {
1703d8085222Sjohnnyhsu@realtek.com 	struct rt5631_priv *rt5631;
1704d8085222Sjohnnyhsu@realtek.com 	int ret;
1705d8085222Sjohnnyhsu@realtek.com 
1706a92b0a08SAxel Lin 	rt5631 = devm_kzalloc(&i2c->dev, sizeof(struct rt5631_priv),
1707a92b0a08SAxel Lin 			      GFP_KERNEL);
1708d8085222Sjohnnyhsu@realtek.com 	if (NULL == rt5631)
1709d8085222Sjohnnyhsu@realtek.com 		return -ENOMEM;
1710d8085222Sjohnnyhsu@realtek.com 
1711d8085222Sjohnnyhsu@realtek.com 	i2c_set_clientdata(i2c, rt5631);
1712d8085222Sjohnnyhsu@realtek.com 
171301476801SMark Brown 	rt5631->regmap = devm_regmap_init_i2c(i2c, &rt5631_regmap_config);
171401476801SMark Brown 	if (IS_ERR(rt5631->regmap))
171501476801SMark Brown 		return PTR_ERR(rt5631->regmap);
171601476801SMark Brown 
171746295e5eSKuninori Morimoto 	ret = devm_snd_soc_register_component(&i2c->dev,
171846295e5eSKuninori Morimoto 			&soc_component_dev_rt5631,
1719d8085222Sjohnnyhsu@realtek.com 			rt5631_dai, ARRAY_SIZE(rt5631_dai));
1720d8085222Sjohnnyhsu@realtek.com 	return ret;
1721d8085222Sjohnnyhsu@realtek.com }
1722d8085222Sjohnnyhsu@realtek.com 
rt5631_i2c_remove(struct i2c_client * client)1723ed5c2f5fSUwe Kleine-König static void rt5631_i2c_remove(struct i2c_client *client)
1724ed5c2f5fSUwe Kleine-König {}
1725d8085222Sjohnnyhsu@realtek.com 
1726f79e5e8cSMark Brown static struct i2c_driver rt5631_i2c_driver = {
1727d8085222Sjohnnyhsu@realtek.com 	.driver = {
1728d8085222Sjohnnyhsu@realtek.com 		.name = "rt5631",
1729189c88ceSKrishna Mohan Dani 		.of_match_table = of_match_ptr(rt5631_i2c_dt_ids),
1730d8085222Sjohnnyhsu@realtek.com 	},
17319abcd240SUwe Kleine-König 	.probe    = rt5631_i2c_probe,
17327a79e94eSBill Pemberton 	.remove   = rt5631_i2c_remove,
1733d8085222Sjohnnyhsu@realtek.com 	.id_table = rt5631_i2c_id,
1734d8085222Sjohnnyhsu@realtek.com };
1735d8085222Sjohnnyhsu@realtek.com 
173603730b87SMark Brown module_i2c_driver(rt5631_i2c_driver);
1737d8085222Sjohnnyhsu@realtek.com 
1738d8085222Sjohnnyhsu@realtek.com MODULE_DESCRIPTION("ASoC RT5631 driver");
1739d8085222Sjohnnyhsu@realtek.com MODULE_AUTHOR("flove <flove@realtek.com>");
1740d8085222Sjohnnyhsu@realtek.com MODULE_LICENSE("GPL");
1741