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