Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid
[sfrench/cifs-2.6.git] / sound / soc / codecs / rt711.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * rt711.h -- RT711 ALSA SoC audio driver header
4  *
5  * Copyright(c) 2019 Realtek Semiconductor Corp.
6  */
7
8 #ifndef __RT711_H__
9 #define __RT711_H__
10
11 extern const struct dev_pm_ops rt711_runtime_pm;
12
13 struct  rt711_priv {
14         struct regmap *regmap;
15         struct regmap *sdw_regmap;
16         struct snd_soc_component *component;
17         struct sdw_slave *slave;
18         enum sdw_slave_status status;
19         struct sdw_bus_params params;
20         bool hw_init;
21         bool first_hw_init;
22         struct snd_soc_jack *hs_jack;
23         struct delayed_work jack_detect_work;
24         struct delayed_work jack_btn_check_work;
25         struct work_struct calibration_work;
26         struct mutex calibrate_mutex; /* for headset calibration */
27         int jack_type, jd_src;
28 };
29
30 struct sdw_stream_data {
31         struct sdw_stream_runtime *sdw_stream;
32 };
33
34 /* NID */
35 #define RT711_AUDIO_FUNCTION_GROUP                      0x01
36 #define RT711_DAC_OUT2                                  0x03
37 #define RT711_ADC_IN1                                   0x09
38 #define RT711_ADC_IN2                                   0x08
39 #define RT711_DMIC1                                     0x12
40 #define RT711_DMIC2                                     0x13
41 #define RT711_MIC2                                      0x19
42 #define RT711_LINE1                                     0x1a
43 #define RT711_LINE2                                     0x1b
44 #define RT711_BEEP                                      0x1d
45 #define RT711_VENDOR_REG                                0x20
46 #define RT711_HP_OUT                                    0x21
47 #define RT711_MIXER_IN1                                 0x22
48 #define RT711_MIXER_IN2                                 0x23
49 #define RT711_INLINE_CMD                                0x55
50 #define RT711_VENDOR_CALI                               0x58
51 #define RT711_VENDOR_IMS_DRE                    0x5b
52
53 /* Index (NID:20h) */
54 #define RT711_DAC_DC_CALI_CTL1                          0x00
55 #define RT711_JD_CTL2                           0x09
56 #define RT711_CC_DET1                           0x11
57 #define RT711_PARA_VERB_CTL                             0x1a
58 #define RT711_COMBO_JACK_AUTO_CTL1                              0x45
59 #define RT711_COMBO_JACK_AUTO_CTL2                              0x46
60 #define RT711_INLINE_CMD_CTL                            0x48
61 #define RT711_DIGITAL_MISC_CTRL4                        0x4a
62 #define RT711_VREFOUT_CTL                               0x6b
63 #define RT711_FSM_CTL                           0x6f
64 #define RT711_IRQ_FLAG_TABLE1                           0x80
65 #define RT711_IRQ_FLAG_TABLE2                           0x81
66 #define RT711_IRQ_FLAG_TABLE3                           0x82
67 #define RT711_TX_RX_MUX_CTL                             0x91
68
69 /* Index (NID:5bh) */
70 #define RT711_IMS_DIGITAL_CTL1                          0x00
71 #define RT711_HP_IMS_RESULT_L                           0x20
72 #define RT711_HP_IMS_RESULT_R                           0x21
73
74 /* Verb */
75 #define RT711_VERB_SET_CONNECT_SEL                      0x3100
76 #define RT711_VERB_SET_EAPD_BTLENABLE                   0x3c00
77 #define RT711_VERB_GET_CONNECT_SEL                      0xb100
78 #define RT711_VERB_SET_POWER_STATE                      0x3500
79 #define RT711_VERB_SET_CHANNEL_STREAMID                 0x3600
80 #define RT711_VERB_SET_PIN_WIDGET_CONTROL               0x3700
81 #define RT711_VERB_SET_UNSOLICITED_ENABLE               0x3800
82 #define RT711_SET_AMP_GAIN_MUTE_H                       0x7300
83 #define RT711_SET_AMP_GAIN_MUTE_L                       0x8380
84 #define RT711_VERB_GET_POWER_STATE                      0xb500
85 #define RT711_VERB_GET_CHANNEL_STREAMID                 0xb600
86 #define RT711_VERB_GET_PIN_SENSE                        0xb900
87 #define RT711_FUNC_RESET                        0xff01
88
89 #define RT711_READ_HDA_3                                0x2012
90 #define RT711_READ_HDA_2                                0x2013
91 #define RT711_READ_HDA_1                                0x2014
92 #define RT711_READ_HDA_0                                0x2015
93 #define RT711_PRIV_INDEX_W_H                            0x7500
94 #define RT711_PRIV_INDEX_W_L                            0x8580
95 #define RT711_PRIV_DATA_W_H                             0x7400
96 #define RT711_PRIV_DATA_W_L                             0x8480
97 #define RT711_PRIV_INDEX_R_H                            0x9d00
98 #define RT711_PRIV_INDEX_R_L                            0xad80
99 #define RT711_PRIV_DATA_R_H                             0x9c00
100 #define RT711_PRIV_DATA_R_L                             0xac80
101 #define RT711_DAC_FORMAT_H                              0x7203
102 #define RT711_DAC_FORMAT_L                              0x8283
103 #define RT711_ADC1_FORMAT_H                             0x7209
104 #define RT711_ADC1_FORMAT_L                             0x8289
105 #define RT711_ADC2_FORMAT_H                             0x7208
106 #define RT711_ADC2_FORMAT_L                             0x8288
107
108 #define RT711_SET_AUDIO_POWER_STATE\
109         (RT711_VERB_SET_POWER_STATE | RT711_AUDIO_FUNCTION_GROUP)
110 #define RT711_GET_AUDIO_POWER_STATE\
111                 (RT711_VERB_GET_POWER_STATE | RT711_AUDIO_FUNCTION_GROUP)
112 #define RT711_SET_PIN_DMIC1\
113         (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_DMIC1)
114 #define RT711_SET_PIN_DMIC2\
115         (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_DMIC2)
116 #define RT711_SET_PIN_HP\
117         (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_HP_OUT)
118 #define RT711_SET_PIN_MIC2\
119         (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_MIC2)
120 #define RT711_SET_PIN_LINE1\
121         (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_LINE1)
122 #define RT711_SET_PIN_LINE2\
123         (RT711_VERB_SET_PIN_WIDGET_CONTROL | RT711_LINE2)
124 #define RT711_SET_MIC2_UNSOLICITED_ENABLE\
125         (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_MIC2)
126 #define RT711_SET_HP_UNSOLICITED_ENABLE\
127         (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_HP_OUT)
128 #define RT711_SET_INLINE_UNSOLICITED_ENABLE\
129         (RT711_VERB_SET_UNSOLICITED_ENABLE | RT711_INLINE_CMD)
130 #define RT711_SET_STREAMID_DAC2\
131         (RT711_VERB_SET_CHANNEL_STREAMID | RT711_DAC_OUT2)
132 #define RT711_SET_STREAMID_ADC1\
133         (RT711_VERB_SET_CHANNEL_STREAMID | RT711_ADC_IN1)
134 #define RT711_SET_STREAMID_ADC2\
135         (RT711_VERB_SET_CHANNEL_STREAMID | RT711_ADC_IN2)
136 #define RT711_GET_STREAMID_DAC2\
137         (RT711_VERB_GET_CHANNEL_STREAMID | RT711_DAC_OUT2)
138 #define RT711_GET_STREAMID_ADC1\
139         (RT711_VERB_GET_CHANNEL_STREAMID | RT711_ADC_IN1)
140 #define RT711_GET_STREAMID_ADC2\
141         (RT711_VERB_GET_CHANNEL_STREAMID | RT711_ADC_IN2)
142 #define RT711_SET_GAIN_DAC2_L\
143         (RT711_SET_AMP_GAIN_MUTE_L | RT711_DAC_OUT2)
144 #define RT711_SET_GAIN_DAC2_H\
145         (RT711_SET_AMP_GAIN_MUTE_H | RT711_DAC_OUT2)
146 #define RT711_SET_GAIN_ADC1_L\
147         (RT711_SET_AMP_GAIN_MUTE_L | RT711_ADC_IN1)
148 #define RT711_SET_GAIN_ADC1_H\
149         (RT711_SET_AMP_GAIN_MUTE_H | RT711_ADC_IN1)
150 #define RT711_SET_GAIN_ADC2_L\
151         (RT711_SET_AMP_GAIN_MUTE_L | RT711_ADC_IN2)
152 #define RT711_SET_GAIN_ADC2_H\
153         (RT711_SET_AMP_GAIN_MUTE_H | RT711_ADC_IN2)
154 #define RT711_SET_GAIN_AMIC_L\
155         (RT711_SET_AMP_GAIN_MUTE_L | RT711_MIC2)
156 #define RT711_SET_GAIN_AMIC_H\
157         (RT711_SET_AMP_GAIN_MUTE_H | RT711_MIC2)
158 #define RT711_SET_GAIN_DMIC1_L\
159         (RT711_SET_AMP_GAIN_MUTE_L | RT711_DMIC1)
160 #define RT711_SET_GAIN_DMIC1_H\
161         (RT711_SET_AMP_GAIN_MUTE_H | RT711_DMIC1)
162 #define RT711_SET_GAIN_DMIC2_L\
163         (RT711_SET_AMP_GAIN_MUTE_L | RT711_DMIC2)
164 #define RT711_SET_GAIN_DMIC2_H\
165         (RT711_SET_AMP_GAIN_MUTE_H | RT711_DMIC2)
166 #define RT711_SET_GAIN_HP_L\
167         (RT711_SET_AMP_GAIN_MUTE_L | RT711_HP_OUT)
168 #define RT711_SET_GAIN_HP_H\
169         (RT711_SET_AMP_GAIN_MUTE_H | RT711_HP_OUT)
170
171 /* DAC DC offset calibration control-1 (0x00)(NID:20h) */
172 #define RT711_DAC_DC_CALI_TRIGGER (0x1 << 15)
173
174 /* jack detect control 2 (0x09)(NID:20h) */
175 #define RT711_JD2_2PORT_200K_DECODE_HP (0x1 << 13)
176 #define RT711_HP_JD_SEL_JD1 (0x0 << 1)
177 #define RT711_HP_JD_SEL_JD2 (0x1 << 1)
178
179 /* CC DET1 (0x11)(NID:20h) */
180 #define RT711_HP_JD_FINAL_RESULT_CTL_JD12 (0x1 << 10)
181 #define RT711_HP_JD_FINAL_RESULT_CTL_CCDET (0x0 << 10)
182
183 /* Parameter & Verb control (0x1a)(NID:20h) */
184 #define RT711_HIDDEN_REG_SW_RESET (0x1 << 14)
185
186 /* combo jack auto switch control 2 (0x46)(NID:20h) */
187 #define RT711_COMBOJACK_AUTO_DET_STATUS                 (0x1 << 11)
188 #define RT711_COMBOJACK_AUTO_DET_TRS                    (0x1 << 10)
189 #define RT711_COMBOJACK_AUTO_DET_CTIA                   (0x1 << 9)
190 #define RT711_COMBOJACK_AUTO_DET_OMTP                   (0x1 << 8)
191
192 /* FSM control (0x6f)(NID:20h) */
193 #define RT711_CALI_CTL                  (0x0 << 0)
194 #define RT711_COMBOJACK_CTL                     (0x1 << 0)
195 #define RT711_IMS_CTL                   (0x2 << 0)
196 #define RT711_DEPOP_CTL                 (0x3 << 0)
197
198 /* Impedance Sense Digital Control 1 (0x00)(NID:5bh) */
199 #define RT711_TRIGGER_IMS                       (0x1 << 15)
200 #define RT711_IMS_EN                    (0x1 << 6)
201
202 #define RT711_EAPD_HIGH                                 0x2
203 #define RT711_EAPD_LOW                                  0x0
204 #define RT711_MUTE_SFT                                  7
205 /* set input/output mapping to payload[14][15] separately */
206 #define RT711_DIR_IN_SFT                                6
207 #define RT711_DIR_OUT_SFT                               7
208
209 enum {
210         RT711_AIF1,
211         RT711_AIF2,
212         RT711_AIFS,
213 };
214
215 enum rt711_jd_src {
216         RT711_JD_NULL,
217         RT711_JD1,
218         RT711_JD2
219 };
220
221 int rt711_io_init(struct device *dev, struct sdw_slave *slave);
222 int rt711_init(struct device *dev, struct regmap *sdw_regmap,
223                struct regmap *regmap, struct sdw_slave *slave);
224
225 int rt711_jack_detect(struct rt711_priv *rt711, bool *hp, bool *mic);
226 int rt711_clock_config(struct device *dev);
227 #endif /* __RT711_H__ */