1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * rt298.h  --  RT298 ALSA SoC audio driver
4  *
5  * Copyright 2011 Realtek Microelectronics
6  * Author: Johnny Hsu <johnnyhsu@realtek.com>
7  */
8 
9 #ifndef __RT298_H__
10 #define __RT298_H__
11 
12 #define VERB_CMD(V, N, D) ((N << 20) | (V << 8) | D)
13 
14 #define RT298_AUDIO_FUNCTION_GROUP			0x01
15 #define RT298_DAC_OUT1					0x02
16 #define RT298_DAC_OUT2					0x03
17 #define RT298_DIG_CVT					0x06
18 #define RT298_ADC_IN1					0x09
19 #define RT298_ADC_IN2					0x08
20 #define RT298_MIXER_IN					0x0b
21 #define RT298_MIXER_OUT1				0x0c
22 #define RT298_MIXER_OUT2				0x0d
23 #define RT298_DMIC1					0x12
24 #define RT298_DMIC2					0x13
25 #define RT298_SPK_OUT					0x14
26 #define RT298_MIC1					0x18
27 #define RT298_LINE1					0x1a
28 #define RT298_BEEP					0x1d
29 #define RT298_SPDIF					0x1e
30 #define RT298_VENDOR_REGISTERS				0x20
31 #define RT298_HP_OUT					0x21
32 #define RT298_MIXER_IN1					0x22
33 #define RT298_MIXER_IN2					0x23
34 #define RT298_INLINE_CMD				0x55
35 
36 #define RT298_SET_PIN_SFT				6
37 #define RT298_SET_PIN_ENABLE				0x40
38 #define RT298_SET_PIN_DISABLE				0
39 #define RT298_SET_EAPD_HIGH				0x2
40 #define RT298_SET_EAPD_LOW				0
41 
42 #define RT298_MUTE_SFT					7
43 
44 /* Verb commands */
45 #define RT298_GET_PARAM(NID, PARAM) VERB_CMD(AC_VERB_PARAMETERS, NID, PARAM)
46 #define RT298_SET_POWER(NID) VERB_CMD(AC_VERB_SET_POWER_STATE, NID, 0)
47 #define RT298_SET_AUDIO_POWER RT298_SET_POWER(RT298_AUDIO_FUNCTION_GROUP)
48 #define RT298_SET_HPO_POWER RT298_SET_POWER(RT298_HP_OUT)
49 #define RT298_SET_SPK_POWER RT298_SET_POWER(RT298_SPK_OUT)
50 #define RT298_SET_DMIC1_POWER RT298_SET_POWER(RT298_DMIC1)
51 #define RT298_SPK_MUX\
52 	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_SPK_OUT, 0)
53 #define RT298_HPO_MUX\
54 	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_HP_OUT, 0)
55 #define RT298_ADC0_MUX\
56 	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_MIXER_IN1, 0)
57 #define RT298_ADC1_MUX\
58 	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_MIXER_IN2, 0)
59 #define RT298_SET_MIC1\
60 	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_MIC1, 0)
61 #define RT298_SET_PIN_HPO\
62 	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_HP_OUT, 0)
63 #define RT298_SET_PIN_SPK\
64 	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_SPK_OUT, 0)
65 #define RT298_SET_PIN_DMIC1\
66 	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_DMIC1, 0)
67 #define RT298_SET_PIN_SPDIF\
68 	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_SPDIF, 0)
69 #define RT298_SET_PIN_DIG_CVT\
70 	VERB_CMD(AC_VERB_SET_DIGI_CONVERT_1, RT298_DIG_CVT, 0)
71 #define RT298_SPK_EAPD\
72 	VERB_CMD(AC_VERB_SET_EAPD_BTLENABLE, RT298_SPK_OUT, 0)
73 #define RT298_SET_AMP_GAIN_HPO\
74 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_HP_OUT, 0)
75 #define RT298_SET_AMP_GAIN_ADC_IN1\
76 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN1, 0)
77 #define RT298_SET_AMP_GAIN_ADC_IN2\
78 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN2, 0)
79 #define RT298_GET_HP_SENSE\
80 	VERB_CMD(AC_VERB_GET_PIN_SENSE, RT298_HP_OUT, 0)
81 #define RT298_GET_MIC1_SENSE\
82 	VERB_CMD(AC_VERB_GET_PIN_SENSE, RT298_MIC1, 0)
83 #define RT298_SET_DMIC2_DEFAULT\
84 	VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT298_DMIC2, 0)
85 #define RT298_SET_SPDIF_DEFAULT\
86 	VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT298_SPDIF, 0)
87 #define RT298_DACL_GAIN\
88 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_DAC_OUT1, 0xa000)
89 #define RT298_DACR_GAIN\
90 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_DAC_OUT1, 0x9000)
91 #define RT298_ADCL_GAIN\
92 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN1, 0x6000)
93 #define RT298_ADCR_GAIN\
94 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN1, 0x5000)
95 #define RT298_MIC_GAIN\
96 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIC1, 0x7000)
97 #define RT298_SPOL_GAIN\
98 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_SPK_OUT, 0xa000)
99 #define RT298_SPOR_GAIN\
100 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_SPK_OUT, 0x9000)
101 #define RT298_HPOL_GAIN\
102 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_HP_OUT, 0xa000)
103 #define RT298_HPOR_GAIN\
104 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_HP_OUT, 0x9000)
105 #define RT298_F_DAC_SWITCH\
106 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_OUT1, 0x7000)
107 #define RT298_F_RECMIX_SWITCH\
108 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_OUT1, 0x7100)
109 #define RT298_REC_MIC_SWITCH\
110 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7000)
111 #define RT298_REC_I2S_SWITCH\
112 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7100)
113 #define RT298_REC_LINE_SWITCH\
114 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7200)
115 #define RT298_REC_BEEP_SWITCH\
116 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7300)
117 #define RT298_DAC_FORMAT\
118 	VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT298_DAC_OUT1, 0)
119 #define RT298_ADC_FORMAT\
120 	VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT298_ADC_IN1, 0)
121 #define RT298_COEF_INDEX\
122 	VERB_CMD(AC_VERB_SET_COEF_INDEX, RT298_VENDOR_REGISTERS, 0)
123 #define RT298_PROC_COEF\
124 	VERB_CMD(AC_VERB_SET_PROC_COEF, RT298_VENDOR_REGISTERS, 0)
125 #define RT298_UNSOLICITED_INLINE_CMD\
126 	VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT298_INLINE_CMD, 0)
127 #define RT298_UNSOLICITED_HP_OUT\
128 	VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT298_HP_OUT, 0)
129 #define RT298_UNSOLICITED_MIC1\
130 	VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT298_MIC1, 0)
131 
132 /* Index registers */
133 #define RT298_A_BIAS_CTRL1	0x01
134 #define RT298_A_BIAS_CTRL2	0x02
135 #define RT298_POWER_CTRL1	0x03
136 #define RT298_A_BIAS_CTRL3	0x04
137 #define RT298_D_FILTER_CTRL	0x05
138 #define RT298_POWER_CTRL2	0x08
139 #define RT298_I2S_CTRL1		0x09
140 #define RT298_I2S_CTRL2		0x0a
141 #define RT298_CLK_DIV		0x0b
142 #define RT298_DC_GAIN		0x0d
143 #define RT298_POWER_CTRL3	0x0f
144 #define RT298_MIC1_DET_CTRL	0x19
145 #define RT298_MISC_CTRL1	0x20
146 #define RT298_IRQ_CTRL		0x33
147 #define RT298_WIND_FILTER_CTRL	0x46
148 #define RT298_PLL_CTRL1		0x49
149 #define RT298_VAD_CTRL		0x4e
150 #define RT298_CBJ_CTRL1		0x4f
151 #define RT298_CBJ_CTRL2		0x50
152 #define RT298_PLL_CTRL		0x63
153 #define RT298_DEPOP_CTRL1	0x66
154 #define RT298_DEPOP_CTRL2	0x67
155 #define RT298_DEPOP_CTRL3	0x68
156 #define RT298_DEPOP_CTRL4	0x69
157 #define RT298_IRQ_FLAG_CTRL	0x7c
158 
159 /* SPDIF (0x06) */
160 #define RT298_SPDIF_SEL_SFT	0
161 #define RT298_SPDIF_SEL_PCM0	0
162 #define RT298_SPDIF_SEL_PCM1	1
163 #define RT298_SPDIF_SEL_SPOUT	2
164 #define RT298_SPDIF_SEL_PP	3
165 
166 /* RECMIX (0x0b) */
167 #define RT298_M_REC_BEEP_SFT	0
168 #define RT298_M_REC_LINE1_SFT	1
169 #define RT298_M_REC_MIC1_SFT	2
170 #define RT298_M_REC_I2S_SFT	3
171 
172 /* Front (0x0c) */
173 #define RT298_M_FRONT_DAC_SFT	0
174 #define RT298_M_FRONT_REC_SFT	1
175 
176 /* SPK-OUT (0x14) */
177 #define RT298_M_SPK_MUX_SFT	14
178 #define RT298_SPK_SEL_MASK	0x1
179 #define RT298_SPK_SEL_SFT	0
180 #define RT298_SPK_SEL_F		0
181 #define RT298_SPK_SEL_S		1
182 
183 /* HP-OUT (0x21) */
184 #define RT298_M_HP_MUX_SFT	14
185 #define RT298_HP_SEL_MASK	0x1
186 #define RT298_HP_SEL_SFT	0
187 #define RT298_HP_SEL_F		0
188 #define RT298_HP_SEL_S		1
189 
190 /* ADC (0x22) (0x23) */
191 #define RT298_ADC_SEL_MASK	0x7
192 #define RT298_ADC_SEL_SFT	0
193 #define RT298_ADC_SEL_SURR	0
194 #define RT298_ADC_SEL_FRONT	1
195 #define RT298_ADC_SEL_DMIC	2
196 #define RT298_ADC_SEL_BEEP	4
197 #define RT298_ADC_SEL_LINE1	5
198 #define RT298_ADC_SEL_I2S	6
199 #define RT298_ADC_SEL_MIC1	7
200 
201 #define RT298_SCLK_S_MCLK	0
202 #define RT298_SCLK_S_PLL	1
203 
204 enum {
205 	RT298_AIF1,
206 	RT298_AIF2,
207 	RT298_AIFS,
208 };
209 
210 int rt298_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack);
211 
212 #endif /* __RT298_H__ */
213 
214