xref: /linux/sound/soc/codecs/rt721-sdca.h (revision 8d084337a32fde0ffa59d5f70d07a54987911ba1)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * rt721-sdca.h -- RT721 SDCA ALSA SoC audio driver header
4  *
5  * Copyright(c) 2024 Realtek Semiconductor Corp.
6  */
7 
8 #ifndef __RT721_H__
9 #define __RT721_H__
10 
11 #include <linux/pm.h>
12 #include <linux/regmap.h>
13 #include <linux/soundwire/sdw.h>
14 #include <linux/soundwire/sdw_type.h>
15 #include <sound/soc.h>
16 #include <linux/workqueue.h>
17 
18 struct  rt721_sdca_priv {
19 	struct regmap *regmap;
20 	struct regmap *mbq_regmap;
21 	struct snd_soc_component *component;
22 	struct sdw_slave *slave;
23 	struct sdw_bus_params params;
24 	bool hw_init;
25 	bool first_hw_init;
26 	struct mutex calibrate_mutex;
27 	struct mutex disable_irq_lock;
28 	bool disable_irq;
29 	/* For Headset jack & Headphone */
30 	unsigned int scp_sdca_stat1;
31 	unsigned int scp_sdca_stat2;
32 	struct snd_soc_jack *hs_jack;
33 	struct delayed_work jack_detect_work;
34 	struct delayed_work jack_btn_check_work;
35 	int jack_type;
36 	int jd_src;
37 	bool fu0f_dapm_mute;
38 	bool fu0f_mixer_l_mute;
39 	bool fu0f_mixer_r_mute;
40 	/* For DMIC */
41 	bool fu1e_dapm_mute;
42 	bool fu1e_mixer_mute[4];
43 };
44 
45 struct rt721_sdca_dmic_kctrl_priv {
46 	unsigned int reg_base;
47 	unsigned int count;
48 	unsigned int max;
49 	unsigned int invert;
50 };
51 
52 /* NID */
53 #define RT721_ANA_POW_PART			0x01
54 #define RT721_DAC_CTRL				0x04
55 #define RT721_JD_CTRL				0x09
56 #define RT721_CBJ_CTRL				0x0a
57 #define RT721_CAP_PORT_CTRL			0x0c
58 #define RT721_CLASD_AMP_CTRL			0x0d
59 #define RT721_BOOST_CTRL			0x0f
60 #define RT721_VENDOR_REG			0x20
61 #define RT721_RC_CALIB_CTRL			0x40
62 #define RT721_VENDOR_EQ_L			0x53
63 #define RT721_VENDOR_EQ_R			0x54
64 #define RT721_VENDOR_HP_CALI			0x56
65 #define RT721_VENDOR_CHARGE_PUMP		0x57
66 #define RT721_VENDOR_CLASD_CALI			0x58
67 #define RT721_VENDOR_IMS_DRE			0x5b
68 #define RT721_VENDOR_SPK_EFUSE			0x5c
69 #define RT721_VENDOR_LEVEL_CTRL			0x5d
70 #define RT721_VENDOR_ANA_CTL			0x5f
71 #define RT721_HDA_SDCA_FLOAT			0x61
72 
73 /* Index (NID:01h) */
74 #define RT721_MBIAS_LV_CTRL2			0x07
75 #define RT721_VREF1_HV_CTRL1			0x0a
76 #define RT721_VREF2_LV_CTRL1			0x0b
77 
78 /* Index (NID:04h) */
79 #define RT721_DAC_2CH_CTRL3			0x02
80 #define RT721_DAC_2CH_CTRL4			0x03
81 
82 /* Index (NID:09h) */
83 #define RT721_JD_1PIN_GAT_CTRL2			0x07
84 
85 /* Index (NID:0ah) */
86 #define RT721_CBJ_A0_GAT_CTRL1			0x04
87 #define RT721_CBJ_A0_GAT_CTRL2			0x05
88 
89 /* Index (NID:0Ch) */
90 #define RT721_HP_AMP_2CH_CAL1			0x05
91 #define RT721_HP_AMP_2CH_CAL4			0x08
92 #define RT721_HP_AMP_2CH_CAL18			0x1b
93 
94 /* Index (NID:0dh) */
95 #define RT721_CLASD_AMP_2CH_CAL			0x14
96 
97 /* Index (NID:0fh) */
98 #define RT721_BST_4CH_TOP_GATING_CTRL1		0x05
99 
100 /* Index (NID:20h) */
101 #define RT721_JD_PRODUCT_NUM			0x00
102 #define RT721_ANALOG_BIAS_CTL3			0x04
103 #define RT721_JD_CTRL1				0x09
104 #define RT721_LDO2_3_CTL1			0x0e
105 #define RT721_GPIO_PAD_CTRL5			0x13
106 #define RT721_LDO1_CTL				0x1a
107 #define RT721_HP_JD_CTRL			0x24
108 #define RT721_VD_HIDDEN_CTRL			0x26
109 #define RT721_CLSD_CTRL6			0x3c
110 #define RT721_COMBO_JACK_AUTO_CTL1		0x45
111 #define RT721_COMBO_JACK_AUTO_CTL2		0x46
112 #define RT721_COMBO_JACK_AUTO_CTL3		0x47
113 #define RT721_DIGITAL_MISC_CTRL4		0x4a
114 #define RT721_VREFO_GAT				0x63
115 #define RT721_FSM_CTL				0x67
116 #define RT721_SDCA_INTR_REC			0x82
117 #define RT721_SW_CONFIG1			0x8a
118 #define RT721_SW_CONFIG2			0x8b
119 
120 /* Index (NID:40h) */
121 #define RT721_RC_CALIB_CTRL0			0x00
122 
123 /* Index (NID:58h) */
124 #define RT721_DAC_DC_CALI_CTL1			0x01
125 #define RT721_DAC_DC_CALI_CTL2			0x02
126 #define RT721_DAC_DC_CALI_CTL3			0x03
127 
128 /* Index (NID:5fh) */
129 #define RT721_MISC_POWER_CTL0			0x00
130 #define RT721_MISC_POWER_CTL31			0x31
131 #define RT721_UAJ_TOP_TCON13			0x44
132 #define RT721_UAJ_TOP_TCON14			0x45
133 #define RT721_UAJ_TOP_TCON17			0x48
134 
135 /* Index (NID:61h) */
136 #define RT721_HDA_LEGACY_MUX_CTL0		0x00
137 #define RT721_HDA_LEGACY_UAJ_CTL		0x02
138 #define RT721_HDA_LEGACY_CTL1			0x05
139 #define RT721_HDA_LEGACY_RESET_CTL		0x06
140 #define RT721_XU_REL_CTRL			0x0c
141 #define RT721_GE_REL_CTRL1			0x0d
142 #define RT721_HDA_LEGACY_GPIO_WAKE_EN_CTL	0x0e
143 #define RT721_GE_SDCA_RST_CTRL			0x10
144 #define RT721_INT_RST_EN_CTRL			0x11
145 #define RT721_XU_EVENT_EN			0x13
146 #define RT721_INLINE_CTL2			0x17
147 #define RT721_UMP_HID_CTRL1			0x18
148 #define RT721_UMP_HID_CTRL2			0x19
149 #define RT721_UMP_HID_CTRL3			0x1a
150 #define RT721_UMP_HID_CTRL4			0x1b
151 #define RT721_UMP_HID_CTRL5			0x1c
152 #define RT721_FUNC_FLOAT_CTL0			0x22
153 #define RT721_FUNC_FLOAT_CTL1			0x23
154 #define RT721_FUNC_FLOAT_CTL2			0x24
155 #define RT721_FUNC_FLOAT_CTL3			0x25
156 #define RT721_ENT_FLOAT_CTL0			0x29
157 #define RT721_ENT_FLOAT_CTL1			0x2c
158 #define RT721_ENT_FLOAT_CTL2			0x2d
159 #define RT721_ENT_FLOAT_CTL3			0x2e
160 #define RT721_ENT_FLOAT_CTL4			0x2f
161 #define RT721_CH_FLOAT_CTL1			0x45
162 #define RT721_CH_FLOAT_CTL2			0x46
163 #define RT721_ENT_FLOAT_CTL5			0x53
164 #define RT721_ENT_FLOAT_CTL6			0x54
165 #define RT721_ENT_FLOAT_CTL7			0x55
166 #define RT721_ENT_FLOAT_CTL8			0x57
167 #define RT721_ENT_FLOAT_CTL9			0x5a
168 #define RT721_ENT_FLOAT_CTL10			0x5b
169 #define RT721_CH_FLOAT_CTL3			0x6a
170 #define RT721_CH_FLOAT_CTL4			0x6d
171 #define RT721_CH_FLOAT_CTL5			0x70
172 #define RT721_CH_FLOAT_CTL6			0x92
173 
174 /* Parameter & Verb control 01 (0x26)(NID:20h) */
175 #define RT721_HIDDEN_REG_SW_RESET (0x1 << 14)
176 
177 /* Buffer address for HID */
178 #define RT721_BUF_ADDR_HID1			0x44030000
179 #define RT721_BUF_ADDR_HID2			0x44030020
180 
181 /* RT721 SDCA Control - function number */
182 #define FUNC_NUM_JACK_CODEC			0x01
183 #define FUNC_NUM_MIC_ARRAY			0x02
184 #define FUNC_NUM_HID				0x03
185 #define FUNC_NUM_AMP				0x04
186 
187 /* RT721 SDCA entity */
188 #define RT721_SDCA_ENT_HID01			0x01
189 #define RT721_SDCA_ENT_XUV			0x03
190 #define RT721_SDCA_ENT_GE49			0x49
191 #define RT721_SDCA_ENT_USER_FU05		0x05
192 #define RT721_SDCA_ENT_USER_FU06		0x06
193 #define RT721_SDCA_ENT_USER_FU0F		0x0f
194 #define RT721_SDCA_ENT_USER_FU10		0x19
195 #define RT721_SDCA_ENT_USER_FU1E		0x1e
196 #define RT721_SDCA_ENT_FU15			0x15
197 #define RT721_SDCA_ENT_PDE23			0x23
198 #define RT721_SDCA_ENT_PDE40			0x40
199 #define RT721_SDCA_ENT_PDE41			0x41
200 #define RT721_SDCA_ENT_PDE11			0x11
201 #define RT721_SDCA_ENT_PDE12			0x12
202 #define RT721_SDCA_ENT_PDE2A			0x2a
203 #define RT721_SDCA_ENT_CS01			0x01
204 #define RT721_SDCA_ENT_CS11			0x11
205 #define RT721_SDCA_ENT_CS1F			0x1f
206 #define RT721_SDCA_ENT_CS1C			0x1c
207 #define RT721_SDCA_ENT_CS31			0x31
208 #define RT721_SDCA_ENT_OT23			0x42
209 #define RT721_SDCA_ENT_IT26			0x26
210 #define RT721_SDCA_ENT_IT09			0x09
211 #define RT721_SDCA_ENT_PLATFORM_FU15		0x15
212 #define RT721_SDCA_ENT_PLATFORM_FU44		0x44
213 #define RT721_SDCA_ENT_XU03			0x03
214 #define RT721_SDCA_ENT_XU0D			0x0d
215 #define RT721_SDCA_ENT_FU55			0x55
216 
217 /* RT721 SDCA control */
218 #define RT721_SDCA_CTL_SAMPLE_FREQ_INDEX		0x10
219 #define RT721_SDCA_CTL_FU_MUTE				0x01
220 #define RT721_SDCA_CTL_FU_VOLUME			0x02
221 #define RT721_SDCA_CTL_HIDTX_CURRENT_OWNER		0x10
222 #define RT721_SDCA_CTL_HIDTX_SET_OWNER_TO_DEVICE	0x11
223 #define RT721_SDCA_CTL_HIDTX_MESSAGE_OFFSET		0x12
224 #define RT721_SDCA_CTL_HIDTX_MESSAGE_LENGTH		0x13
225 #define RT721_SDCA_CTL_SELECTED_MODE			0x01
226 #define RT721_SDCA_CTL_DETECTED_MODE			0x02
227 #define RT721_SDCA_CTL_REQ_POWER_STATE			0x01
228 #define RT721_SDCA_CTL_VENDOR_DEF			0x30
229 #define RT721_SDCA_CTL_XUV				0x34
230 #define RT721_SDCA_CTL_FU_CH_GAIN			0x0b
231 
232 /* RT721 SDCA channel */
233 #define CH_L	0x01
234 #define CH_R	0x02
235 #define CH_01	0x01
236 #define CH_02	0x02
237 #define CH_03	0x03
238 #define CH_04	0x04
239 #define CH_08	0x08
240 #define CH_09	0x09
241 #define CH_0A	0x0a
242 
243 /* sample frequency index */
244 #define RT721_SDCA_RATE_8000HZ		0x01
245 #define RT721_SDCA_RATE_11025HZ		0x02
246 #define RT721_SDCA_RATE_12000HZ		0x03
247 #define RT721_SDCA_RATE_16000HZ		0x04
248 #define RT721_SDCA_RATE_22050HZ		0x05
249 #define RT721_SDCA_RATE_24000HZ		0x06
250 #define RT721_SDCA_RATE_32000HZ		0x07
251 #define RT721_SDCA_RATE_44100HZ		0x08
252 #define RT721_SDCA_RATE_48000HZ		0x09
253 #define RT721_SDCA_RATE_88200HZ		0x0a
254 #define RT721_SDCA_RATE_96000HZ		0x0b
255 #define RT721_SDCA_RATE_176400HZ	0x0c
256 #define RT721_SDCA_RATE_192000HZ	0x0d
257 #define RT721_SDCA_RATE_384000HZ	0x0e
258 #define RT721_SDCA_RATE_768000HZ	0x0f
259 
260 /* RT721 HID ID */
261 #define RT721_SDCA_HID_ID		0x11
262 
263 enum {
264 	RT721_AIF1, /* For headset mic and headphone */
265 	RT721_AIF2, /* For speaker */
266 	RT721_AIF3, /* For dmic */
267 	RT721_AIFS,
268 };
269 
270 int rt721_sdca_io_init(struct device *dev, struct sdw_slave *slave);
271 int rt721_sdca_init(struct device *dev, struct regmap *regmap,
272 			struct regmap *mbq_regmap, struct sdw_slave *slave);
273 #endif /* __RT721_H__ */
274