xref: /OK3568_Linux_fs/kernel/sound/soc/codecs/rk817_codec.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (c) 2018 Rockchip Electronics Co. Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14 
15 #ifndef __RK817_CODEC_H__
16 #define __RK817_CODEC_H__
17 
18 /* codec register */
19 #define RK817_CODEC_BASE		0x0000
20 
21 #define RK817_CODEC_DTOP_VUCTL		(RK817_CODEC_BASE + 0x12)
22 #define RK817_CODEC_DTOP_VUCTIME	(RK817_CODEC_BASE + 0x13)
23 #define RK817_CODEC_DTOP_LPT_SRST	(RK817_CODEC_BASE + 0x14)
24 #define RK817_CODEC_DTOP_DIGEN_CLKE	(RK817_CODEC_BASE + 0x15)
25 #define RK817_CODEC_AREF_RTCFG0		(RK817_CODEC_BASE + 0x16)
26 #define RK817_CODEC_AREF_RTCFG1		(RK817_CODEC_BASE + 0x17)
27 #define RK817_CODEC_AADC_CFG0		(RK817_CODEC_BASE + 0x18)
28 #define RK817_CODEC_AADC_CFG1		(RK817_CODEC_BASE + 0x19)
29 #define RK817_CODEC_DADC_VOLL		(RK817_CODEC_BASE + 0x1a)
30 #define RK817_CODEC_DADC_VOLR		(RK817_CODEC_BASE + 0x1b)
31 #define RK817_CODEC_DADC_SR_ACL0	(RK817_CODEC_BASE + 0x1e)
32 #define RK817_CODEC_DADC_ALC1		(RK817_CODEC_BASE + 0x1f)
33 #define RK817_CODEC_DADC_ALC2		(RK817_CODEC_BASE + 0x20)
34 #define RK817_CODEC_DADC_NG		(RK817_CODEC_BASE + 0x21)
35 #define RK817_CODEC_DADC_HPF		(RK817_CODEC_BASE + 0x22)
36 #define RK817_CODEC_DADC_RVOLL		(RK817_CODEC_BASE + 0x23)
37 #define RK817_CODEC_DADC_RVOLR		(RK817_CODEC_BASE + 0x24)
38 #define RK817_CODEC_AMIC_CFG0		(RK817_CODEC_BASE + 0x27)
39 #define RK817_CODEC_AMIC_CFG1		(RK817_CODEC_BASE + 0x28)
40 #define RK817_CODEC_DMIC_PGA_GAIN	(RK817_CODEC_BASE + 0x29)
41 #define RK817_CODEC_DMIC_LMT1		(RK817_CODEC_BASE + 0x2a)
42 #define RK817_CODEC_DMIC_LMT2		(RK817_CODEC_BASE + 0x2b)
43 #define RK817_CODEC_DMIC_NG1		(RK817_CODEC_BASE + 0x2c)
44 #define RK817_CODEC_DMIC_NG2		(RK817_CODEC_BASE + 0x2d)
45 #define RK817_CODEC_ADAC_CFG0		(RK817_CODEC_BASE + 0x2e)
46 #define RK817_CODEC_ADAC_CFG1		(RK817_CODEC_BASE + 0x2f)
47 #define RK817_CODEC_DDAC_POPD_DACST	(RK817_CODEC_BASE + 0x30)
48 #define RK817_CODEC_DDAC_VOLL		(RK817_CODEC_BASE + 0x31)
49 #define RK817_CODEC_DDAC_VOLR		(RK817_CODEC_BASE + 0x32)
50 #define RK817_CODEC_DDAC_SR_LMT0	(RK817_CODEC_BASE + 0x35)
51 #define RK817_CODEC_DDAC_LMT1		(RK817_CODEC_BASE + 0x36)
52 #define RK817_CODEC_DDAC_LMT2		(RK817_CODEC_BASE + 0x37)
53 #define RK817_CODEC_DDAC_MUTE_MIXCTL	(RK817_CODEC_BASE + 0x38)
54 #define RK817_CODEC_DDAC_RVOLL		(RK817_CODEC_BASE + 0x39)
55 #define RK817_CODEC_DDAC_RVOLR		(RK817_CODEC_BASE + 0x3a)
56 #define RK817_CODEC_AHP_ANTI0		(RK817_CODEC_BASE + 0x3b)
57 #define RK817_CODEC_AHP_ANTI1		(RK817_CODEC_BASE + 0x3c)
58 #define RK817_CODEC_AHP_CFG0		(RK817_CODEC_BASE + 0x3d)
59 #define RK817_CODEC_AHP_CFG1		(RK817_CODEC_BASE + 0x3e)
60 #define RK817_CODEC_AHP_CP		(RK817_CODEC_BASE + 0x3f)
61 #define RK817_CODEC_ACLASSD_CFG1	(RK817_CODEC_BASE + 0x40)
62 #define RK817_CODEC_ACLASSD_CFG2	(RK817_CODEC_BASE + 0x41)
63 #define RK817_CODEC_APLL_CFG0		(RK817_CODEC_BASE + 0x42)
64 #define RK817_CODEC_APLL_CFG1		(RK817_CODEC_BASE + 0x43)
65 #define RK817_CODEC_APLL_CFG2		(RK817_CODEC_BASE + 0x44)
66 #define RK817_CODEC_APLL_CFG3		(RK817_CODEC_BASE + 0x45)
67 #define RK817_CODEC_APLL_CFG4		(RK817_CODEC_BASE + 0x46)
68 #define RK817_CODEC_APLL_CFG5		(RK817_CODEC_BASE + 0x47)
69 #define RK817_CODEC_DI2S_CKM		(RK817_CODEC_BASE + 0x48)
70 #define RK817_CODEC_DI2S_RSD		(RK817_CODEC_BASE + 0x49)
71 #define RK817_CODEC_DI2S_RXCR1		(RK817_CODEC_BASE + 0x4a)
72 #define RK817_CODEC_DI2S_RXCR2		(RK817_CODEC_BASE + 0x4b)
73 #define RK817_CODEC_DI2S_RXCMD_TSD	(RK817_CODEC_BASE + 0x4c)
74 #define RK817_CODEC_DI2S_TXCR1		(RK817_CODEC_BASE + 0x4d)
75 #define RK817_CODEC_DI2S_TXCR2		(RK817_CODEC_BASE + 0x4e)
76 #define RK817_CODEC_DI2S_TXCR3_TXCMD	(RK817_CODEC_BASE + 0x4f)
77 #define RK817_PMIC_CHIP_NAME		(RK817_CODEC_BASE + 0xed)
78 #define RK817_PMIC_CHIP_VER		(RK817_CODEC_BASE + 0xee)
79 
80 /* RK817_CODEC_DTOP_DIGEN_CLKE */
81 #define ADC_DIG_CLK_MASK		(0xf << 4)
82 #define ADC_DIG_CLK_SFT			4
83 #define ADC_DIG_CLK_DIS			(0x0 << 4)
84 #define ADC_DIG_CLK_EN			(0xf << 4)
85 
86 #define I2STX_CKE_EN			(0x1 << 6)
87 #define I2STX_CKE_DIS			(0x0 << 6)
88 
89 #define DAC_DIG_CLK_MASK		(0xf << 0)
90 #define DAC_DIG_CLK_SFT			0
91 #define DAC_DIG_CLK_DIS			(0x0 << 0)
92 #define DAC_DIG_CLK_EN			(0xf << 0)
93 
94 /* RK817_CODEC_APLL_CFG5 */
95 #define PLL_PW_DOWN			(0x01 << 0)
96 #define PLL_PW_UP			(0x00 << 0)
97 
98 /* RK817_CODEC_DI2S_CKM */
99 #define PDM_EN_MASK			(0x1 << 3)
100 #define PDM_EN_SFT			3
101 #define PDM_EN_DISABLE			(0x0 << 3)
102 #define PDM_EN_ENABLE			(0x1 << 3)
103 
104 #define SCK_EN_ENABLE			(0x1 << 2)
105 #define SCK_EN_DISABLE			(0x0 << 2)
106 
107 #define RK817_I2S_MODE_MASK		(0x1 << 0)
108 #define RK817_I2S_MODE_SFT		0
109 #define RK817_I2S_MODE_MST		(0x1 << 0)
110 #define RK817_I2S_MODE_SLV		(0x0 << 0)
111 
112 /* RK817_CODEC_DDAC_SR_LMT0 */
113 #define DACSRT_MASK			(0x7 << 0)
114 
115 /* RK817_CODEC_DDAC_MUTE_MIXCTL */
116 #define DACMT_ENABLE			(0x1 << 0)
117 #define DACMT_DISABLE			(0x0 << 0)
118 
119 /* RK817_CODEC_DI2S_RXCR2 */
120 #define VDW_RX_24BITS			(0x17)
121 #define VDW_RX_16BITS			(0x0f)
122 /* RK817_CODEC_DI2S_TXCR2 */
123 #define VDW_TX_24BITS			(0x17)
124 #define VDW_TX_16BITS			(0x0f)
125 
126 /* RK817_CODEC_AHP_CFG1 */
127 #define HP_ANTIPOP_ENABLE		(0x1 << 4)
128 #define HP_ANTIPOP_DISABLE		(0x0 << 4)
129 
130 /* RK817_CODEC_ADAC_CFG1 */
131 #define PWD_DACBIAS_MASK		(0x1 << 3)
132 #define PWD_DACBIAS_SFT			3
133 #define PWD_DACBIAS_DOWN		(0x1 << 3)
134 #define PWD_DACBIAS_ON			(0x0 << 3)
135 
136 #define PWD_DACD_MASK			(0x1 << 2)
137 #define PWD_DACD_SFT			2
138 #define PWD_DACD_DOWN			(0x1 << 2)
139 #define PWD_DACD_ON			(0x0 << 2)
140 
141 #define PWD_DACL_MASK			(0x1 << 1)
142 #define PWD_DACL_SFT			1
143 #define PWD_DACL_DOWN			(0x1 << 1)
144 #define PWD_DACL_ON			(0x0 << 1)
145 
146 #define PWD_DACR_MASK			(0x1 << 0)
147 #define PWD_DACR_SFT			0
148 #define PWD_DACR_DOWN			(0x1 << 0)
149 #define PWD_DACR_ON			(0x0 << 0)
150 
151 /* RK817_CODEC_AADC_CFG0 */
152 #define ADC_L_PWD_MASK			(0x1 << 7)
153 #define ADC_L_PWD_SFT			7
154 #define ADC_L_PWD_DIS			(0x0 << 7)
155 #define ADC_L_PWD_EN			(0x1 << 7)
156 
157 #define ADC_R_PWD_MASK			(0x1 << 6)
158 #define ADC_R_PWD_SFT			6
159 #define ADC_R_PWD_DIS			(0x0 << 6)
160 #define ADC_R_PWD_EN			(0x1 << 6)
161 
162 /* RK817_CODEC_AMIC_CFG0 */
163 #define MIC_DIFF_MASK			(0x1 << 7)
164 #define MIC_DIFF_SFT			7
165 #define MIC_DIFF_DIS			(0x0 << 7)
166 #define MIC_DIFF_EN			(0x1 << 7)
167 
168 #define PWD_PGA_L_MASK			(0x1 << 5)
169 #define PWD_PGA_L_SFT			5
170 #define PWD_PGA_L_DIS			(0x0 << 5)
171 #define PWD_PGA_L_EN			(0x1 << 5)
172 
173 #define PWD_PGA_R_MASK			(0x1 << 4)
174 #define PWD_PGA_R_SFT			4
175 #define PWD_PGA_R_DIS			(0x0 << 4)
176 #define PWD_PGA_R_EN			(0x1 << 4)
177 
178 enum {
179 	RK817_HIFI,
180 	RK817_VOICE,
181 };
182 
183 enum {
184 	RK817_MONO = 1,
185 	RK817_STEREO,
186 };
187 
188 enum {
189 	OFF,
190 	RCV,
191 	SPK_PATH,
192 	HP_PATH,
193 	HP_NO_MIC,
194 	BT,
195 	SPK_HP,
196 	RING_SPK,
197 	RING_HP,
198 	RING_HP_NO_MIC,
199 	RING_SPK_HP,
200 };
201 
202 enum {
203 	MIC_OFF,
204 	MAIN_MIC,
205 	HANDS_FREE_MIC,
206 	BT_SCO_MIC,
207 };
208 
209 struct rk817_reg_val_typ {
210 	unsigned int reg;
211 	unsigned int value;
212 };
213 
214 struct rk817_init_bit_typ {
215 	unsigned int reg;
216 	unsigned int power_bit;
217 	unsigned int init_bit;
218 };
219 
220 #endif /* __RK817_CODEC_H__ */
221