xref: /linux/sound/soc/codecs/rt274.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2c7e79b2bSBard Liao /*
3c7e79b2bSBard Liao  * rt274.h  --  RT274 ALSA SoC audio driver
4c7e79b2bSBard Liao  *
5c7e79b2bSBard Liao  * Copyright 2016 Realtek Microelectronics
6c7e79b2bSBard Liao  * Author: Bard Liao <bardliao@realtek.com>
7c7e79b2bSBard Liao  */
8c7e79b2bSBard Liao 
9c7e79b2bSBard Liao #ifndef __RT274_H__
10c7e79b2bSBard Liao #define __RT274_H__
11c7e79b2bSBard Liao 
12c7e79b2bSBard Liao #define VERB_CMD(V, N, D) ((N << 20) | (V << 8) | D)
13c7e79b2bSBard Liao 
14c7e79b2bSBard Liao #define RT274_AUDIO_FUNCTION_GROUP			0x01
15c7e79b2bSBard Liao #define RT274_DAC_OUT0					0x02
16c7e79b2bSBard Liao #define RT274_DAC_OUT1					0x03
17c7e79b2bSBard Liao #define RT274_ADC_IN2					0x08
18c7e79b2bSBard Liao #define RT274_ADC_IN1					0x09
19c7e79b2bSBard Liao #define RT274_DIG_CVT					0x0a
20c7e79b2bSBard Liao #define RT274_DMIC1					0x12
21c7e79b2bSBard Liao #define RT274_DMIC2					0x13
22c7e79b2bSBard Liao #define RT274_MIC					0x19
23c7e79b2bSBard Liao #define RT274_LINE1					0x1a
24c7e79b2bSBard Liao #define RT274_LINE2					0x1b
25c7e79b2bSBard Liao #define RT274_LINE3					0x16
26c7e79b2bSBard Liao #define RT274_SPDIF					0x1e
27c7e79b2bSBard Liao #define RT274_VENDOR_REGISTERS				0x20
28c7e79b2bSBard Liao #define RT274_HP_OUT					0x21
29c7e79b2bSBard Liao #define RT274_MIXER_IN1					0x22
30c7e79b2bSBard Liao #define RT274_MIXER_IN2					0x23
31c7e79b2bSBard Liao #define RT274_INLINE_CMD				0x55
32c7e79b2bSBard Liao 
33c7e79b2bSBard Liao #define RT274_SET_PIN_SFT				6
34c7e79b2bSBard Liao #define RT274_SET_PIN_ENABLE				0x40
35c7e79b2bSBard Liao #define RT274_SET_PIN_DISABLE				0
36c7e79b2bSBard Liao #define RT274_SET_EAPD_HIGH				0x2
37c7e79b2bSBard Liao #define RT274_SET_EAPD_LOW				0
38c7e79b2bSBard Liao 
39c7e79b2bSBard Liao #define RT274_MUTE_SFT					7
40c7e79b2bSBard Liao 
41c7e79b2bSBard Liao /* Verb commands */
42c7e79b2bSBard Liao #define RT274_RESET\
43c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_CODEC_RESET, RT274_AUDIO_FUNCTION_GROUP, 0)
44c7e79b2bSBard Liao #define RT274_GET_PARAM(NID, PARAM) VERB_CMD(AC_VERB_PARAMETERS, NID, PARAM)
45c7e79b2bSBard Liao #define RT274_SET_POWER(NID) VERB_CMD(AC_VERB_SET_POWER_STATE, NID, 0)
46c7e79b2bSBard Liao #define RT274_SET_AUDIO_POWER RT274_SET_POWER(RT274_AUDIO_FUNCTION_GROUP)
47c7e79b2bSBard Liao #define RT274_SET_HPO_POWER RT274_SET_POWER(RT274_HP_OUT)
48c7e79b2bSBard Liao #define RT274_SET_DMIC1_POWER RT274_SET_POWER(RT274_DMIC1)
49c7e79b2bSBard Liao #define RT274_LOUT_MUX\
50c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_LINE3, 0)
51c7e79b2bSBard Liao #define RT274_HPO_MUX\
52c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_HP_OUT, 0)
53c7e79b2bSBard Liao #define RT274_ADC0_MUX\
54c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_MIXER_IN1, 0)
55c7e79b2bSBard Liao #define RT274_ADC1_MUX\
56c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT274_MIXER_IN2, 0)
57c7e79b2bSBard Liao #define RT274_SET_MIC\
58c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_MIC, 0)
59c7e79b2bSBard Liao #define RT274_SET_PIN_LOUT3\
60c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_LINE3, 0)
61c7e79b2bSBard Liao #define RT274_SET_PIN_HPO\
62c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_HP_OUT, 0)
63c7e79b2bSBard Liao #define RT274_SET_PIN_DMIC1\
64c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_DMIC1, 0)
65c7e79b2bSBard Liao #define RT274_SET_PIN_SPDIF\
66c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT274_SPDIF, 0)
67c7e79b2bSBard Liao #define RT274_SET_PIN_DIG_CVT\
68c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_DIGI_CONVERT_1, RT274_DIG_CVT, 0)
69c7e79b2bSBard Liao #define RT274_SET_AMP_GAIN_HPO\
70c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_HP_OUT, 0)
71c7e79b2bSBard Liao #define RT274_SET_AMP_GAIN_ADC_IN1\
72c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN1, 0)
73c7e79b2bSBard Liao #define RT274_SET_AMP_GAIN_ADC_IN2\
74c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN2, 0)
75c7e79b2bSBard Liao #define RT274_GET_HP_SENSE\
76c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_GET_PIN_SENSE, RT274_HP_OUT, 0)
77c7e79b2bSBard Liao #define RT274_GET_MIC_SENSE\
78c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_GET_PIN_SENSE, RT274_MIC, 0)
79c7e79b2bSBard Liao #define RT274_SET_DMIC2_DEFAULT\
80c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT274_DMIC2, 0)
81c7e79b2bSBard Liao #define RT274_SET_SPDIF_DEFAULT\
82c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT274_SPDIF, 0)
83c7e79b2bSBard Liao #define RT274_DAC0L_GAIN\
84c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT0, 0xa000)
85c7e79b2bSBard Liao #define RT274_DAC0R_GAIN\
86c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT0, 0x9000)
87c7e79b2bSBard Liao #define RT274_DAC1L_GAIN\
88c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT1, 0xa000)
89c7e79b2bSBard Liao #define RT274_DAC1R_GAIN\
90c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_DAC_OUT1, 0x9000)
91c7e79b2bSBard Liao #define RT274_ADCL_GAIN\
92c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN1, 0x6000)
93c7e79b2bSBard Liao #define RT274_ADCR_GAIN\
94c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_ADC_IN1, 0x5000)
95c7e79b2bSBard Liao #define RT274_MIC_GAIN\
96c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_MIC, 0x7000)
97c7e79b2bSBard Liao #define RT274_LOUTL_GAIN\
98c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_LINE3, 0xa000)
99c7e79b2bSBard Liao #define RT274_LOUTR_GAIN\
100c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_LINE3, 0x9000)
101c7e79b2bSBard Liao #define RT274_HPOL_GAIN\
102c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_HP_OUT, 0xa000)
103c7e79b2bSBard Liao #define RT274_HPOR_GAIN\
104c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT274_HP_OUT, 0x9000)
105c7e79b2bSBard Liao #define RT274_DAC_FORMAT\
106c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT274_DAC_OUT0, 0)
107c7e79b2bSBard Liao #define RT274_ADC_FORMAT\
108c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT274_ADC_IN1, 0)
109c7e79b2bSBard Liao #define RT274_COEF_INDEX\
110c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_COEF_INDEX, RT274_VENDOR_REGISTERS, 0)
111c7e79b2bSBard Liao #define RT274_PROC_COEF\
112c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_PROC_COEF, RT274_VENDOR_REGISTERS, 0)
113c7e79b2bSBard Liao #define RT274_UNSOLICITED_INLINE_CMD\
114c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT274_INLINE_CMD, 0)
115c7e79b2bSBard Liao #define RT274_UNSOLICITED_HP_OUT\
116c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT274_HP_OUT, 0)
117c7e79b2bSBard Liao #define RT274_UNSOLICITED_MIC\
118c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_UNSOLICITED_ENABLE, RT274_MIC, 0)
119c7e79b2bSBard Liao #define RT274_COEF58_INDEX\
120c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_COEF_INDEX, 0x58, 0)
121c7e79b2bSBard Liao #define RT274_COEF58_COEF\
122c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_PROC_COEF, 0x58, 0)
123c7e79b2bSBard Liao #define RT274_COEF5b_INDEX\
124c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_COEF_INDEX, 0x5b, 0)
125c7e79b2bSBard Liao #define RT274_COEF5b_COEF\
126c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_PROC_COEF, 0x5b, 0)
127c7e79b2bSBard Liao #define RT274_SET_STREAMID_DAC0\
128c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_DAC_OUT0, 0)
129c7e79b2bSBard Liao #define RT274_SET_STREAMID_DAC1\
130c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_DAC_OUT1, 0)
131c7e79b2bSBard Liao #define RT274_SET_STREAMID_ADC1\
132c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_ADC_IN1, 0)
133c7e79b2bSBard Liao #define RT274_SET_STREAMID_ADC2\
134c7e79b2bSBard Liao 	VERB_CMD(AC_VERB_SET_CHANNEL_STREAMID, RT274_ADC_IN2, 0)
135c7e79b2bSBard Liao 
136c7e79b2bSBard Liao /* Index registers */
137c7e79b2bSBard Liao #define RT274_EAPD_GPIO_IRQ_CTRL	0x10
138c7e79b2bSBard Liao #define RT274_PAD_CTRL12		0x35
139c7e79b2bSBard Liao #define RT274_I2S_CTRL1			0x63
140c7e79b2bSBard Liao #define RT274_I2S_CTRL2			0x64
141c7e79b2bSBard Liao #define RT274_MCLK_CTRL			0x71
142c7e79b2bSBard Liao #define RT274_CLK_CTRL			0x72
143c7e79b2bSBard Liao #define RT274_PLL2_CTRL			0x7b
144c7e79b2bSBard Liao 
145c7e79b2bSBard Liao 
146c7e79b2bSBard Liao /* EAPD GPIO IRQ control (Index 0x10) */
147c7e79b2bSBard Liao #define RT274_IRQ_DIS		(0x0 << 13)
148c7e79b2bSBard Liao #define RT274_IRQ_EN		(0x1 << 13)
149c7e79b2bSBard Liao #define RT274_IRQ_CLR		(0x1 << 12)
150c7e79b2bSBard Liao #define RT274_GPI2_SEL_MASK	(0x3 << 7)
151c7e79b2bSBard Liao #define RT274_GPI2_SEL_GPIO2	(0x0 << 7)
152c7e79b2bSBard Liao #define RT274_GPI2_SEL_I2S	(0x1 << 7)
153c7e79b2bSBard Liao #define RT274_GPI2_SEL_DMIC_CLK	(0x2 << 7)
154c7e79b2bSBard Liao #define RT274_GPI2_SEL_CBJ	(0x3 << 7)
155c7e79b2bSBard Liao 
156c7e79b2bSBard Liao /* Front I2S_Interface control 1 (Index 0x63) */
157c7e79b2bSBard Liao #define RT274_I2S_MODE_MASK	(0x1 << 11)
158c7e79b2bSBard Liao #define RT274_I2S_MODE_S	(0x0 << 11)
159c7e79b2bSBard Liao #define RT274_I2S_MODE_M	(0x1 << 11)
160c7e79b2bSBard Liao #define RT274_TDM_DIS		(0x0 << 10)
161c7e79b2bSBard Liao #define RT274_TDM_EN		(0x1 << 10)
162c7e79b2bSBard Liao #define RT274_TDM_CH_NUM	(0x1 << 7)
163c7e79b2bSBard Liao #define RT274_TDM_2CH		(0x0 << 7)
164c7e79b2bSBard Liao #define RT274_TDM_4CH		(0x1 << 7)
165c7e79b2bSBard Liao #define RT274_I2S_FMT_MASK	(0x3 << 8)
166c7e79b2bSBard Liao #define RT274_I2S_FMT_I2S	(0x0 << 8)
167c7e79b2bSBard Liao #define RT274_I2S_FMT_LJ	(0x1 << 8)
168c7e79b2bSBard Liao #define RT274_I2S_FMT_PCMA	(0x2 << 8)
169c7e79b2bSBard Liao #define RT274_I2S_FMT_PCMB	(0x3 << 8)
170c7e79b2bSBard Liao 
171c7e79b2bSBard Liao /* MCLK clock domain control (Index 0x71) */
172c7e79b2bSBard Liao #define RT274_MCLK_MODE_MASK	(0x1 << 14)
173c7e79b2bSBard Liao #define RT274_MCLK_MODE_DIS	(0x0 << 14)
174c7e79b2bSBard Liao #define RT274_MCLK_MODE_EN	(0x1 << 14)
175c7e79b2bSBard Liao 
176c7e79b2bSBard Liao /* Clock control (Index 0x72) */
177c7e79b2bSBard Liao #define RT274_CLK_SRC_MASK	(0x7 << 3)
178c7e79b2bSBard Liao #define RT274_CLK_SRC_MCLK	(0x0 << 3)
179c7e79b2bSBard Liao #define RT274_CLK_SRC_PLL2	(0x3 << 3)
180c7e79b2bSBard Liao 
181c7e79b2bSBard Liao /* PLL2 control (Index 0x7b) */
182c7e79b2bSBard Liao #define RT274_PLL2_SRC_MASK	(0x1 << 13)
183c7e79b2bSBard Liao #define RT274_PLL2_SRC_MCLK	(0x0 << 13)
184c7e79b2bSBard Liao #define RT274_PLL2_SRC_BCLK	(0x1 << 13)
185c7e79b2bSBard Liao 
186c7e79b2bSBard Liao /* HP-OUT (0x21) */
187c7e79b2bSBard Liao #define RT274_M_HP_MUX_SFT	14
188c7e79b2bSBard Liao #define RT274_HP_SEL_MASK	0x1
189c7e79b2bSBard Liao #define RT274_HP_SEL_SFT	0
190c7e79b2bSBard Liao #define RT274_HP_SEL_F		0
191c7e79b2bSBard Liao #define RT274_HP_SEL_S		1
192c7e79b2bSBard Liao 
193c7e79b2bSBard Liao /* ADC (0x22) (0x23) */
194c7e79b2bSBard Liao #define RT274_ADC_SEL_MASK	0x7
195c7e79b2bSBard Liao #define RT274_ADC_SEL_SFT	0
196c7e79b2bSBard Liao #define RT274_ADC_SEL_MIC	0
197c7e79b2bSBard Liao #define RT274_ADC_SEL_LINE1	1
198c7e79b2bSBard Liao #define RT274_ADC_SEL_LINE2	2
199c7e79b2bSBard Liao #define RT274_ADC_SEL_DMIC	3
200c7e79b2bSBard Liao 
201c7e79b2bSBard Liao #define RT274_SCLK_S_MCLK	0
202c7e79b2bSBard Liao #define RT274_SCLK_S_PLL1	1
203c7e79b2bSBard Liao #define RT274_SCLK_S_PLL2	2
204c7e79b2bSBard Liao 
205c7e79b2bSBard Liao #define RT274_PLL2_S_MCLK	0
206c7e79b2bSBard Liao #define RT274_PLL2_S_BCLK	1
207c7e79b2bSBard Liao 
208c7e79b2bSBard Liao enum {
209c7e79b2bSBard Liao 	RT274_AIF1,
210c7e79b2bSBard Liao 	RT274_AIFS,
211c7e79b2bSBard Liao };
212c7e79b2bSBard Liao 
213c7e79b2bSBard Liao #endif /* __RT274_H__ */
214c7e79b2bSBard Liao 
215