xref: /openbmc/linux/sound/soc/codecs/rt700.h (revision fa840ba4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * rt700.h -- RT700 ALSA SoC audio driver header
4  *
5  * Copyright(c) 2019 Realtek Semiconductor Corp.
6  */
7 
8 #ifndef __RT700_H__
9 #define __RT700_H__
10 
11 extern const struct dev_pm_ops rt700_runtime_pm;
12 
13 struct  rt700_priv {
14 	struct snd_soc_component *component;
15 	struct regmap *regmap;
16 	struct regmap *sdw_regmap;
17 	struct sdw_slave *slave;
18 	struct sdw_bus_params params;
19 	bool hw_init;
20 	bool first_hw_init;
21 	struct snd_soc_jack *hs_jack;
22 	struct delayed_work jack_detect_work;
23 	struct delayed_work jack_btn_check_work;
24 	int jack_type;
25 	struct mutex disable_irq_lock; /* imp-def irq lock protection */
26 	bool disable_irq;
27 };
28 
29 /* NID */
30 #define RT700_AUDIO_FUNCTION_GROUP			0x01
31 #define RT700_DAC_OUT1					0x02
32 #define RT700_DAC_OUT2					0x03
33 #define RT700_ADC_IN1					0x09
34 #define RT700_ADC_IN2					0x08
35 #define RT700_DMIC1					0x12
36 #define RT700_DMIC2					0x13
37 #define RT700_SPK_OUT					0x14
38 #define RT700_MIC2					0x19
39 #define RT700_LINE1					0x1a
40 #define RT700_LINE2					0x1b
41 #define RT700_BEEP					0x1d
42 #define RT700_SPDIF					0x1e
43 #define RT700_VENDOR_REGISTERS				0x20
44 #define RT700_HP_OUT					0x21
45 #define RT700_MIXER_IN1					0x22
46 #define RT700_MIXER_IN2					0x23
47 #define RT700_INLINE_CMD				0x55
48 
49 /* Index (NID:20h) */
50 #define RT700_DAC_DC_CALI_CTL1				0x00
51 #define RT700_PARA_VERB_CTL				0x1a
52 #define RT700_COMBO_JACK_AUTO_CTL1				0x45
53 #define RT700_COMBO_JACK_AUTO_CTL2				0x46
54 #define RT700_INLINE_CMD_CTL				0x48
55 #define RT700_DIGITAL_MISC_CTRL4			0x4a
56 #define RT700_VREFOUT_CTL				0x6b
57 #define RT700_FSM_CTL				0x6f
58 #define RT700_IRQ_FLAG_TABLE1				0x80
59 #define RT700_IRQ_FLAG_TABLE2				0x81
60 #define RT700_IRQ_FLAG_TABLE3				0x82
61 
62 /* Verb */
63 #define RT700_VERB_SET_CONNECT_SEL			0x3100
64 #define RT700_VERB_SET_EAPD_BTLENABLE			0x3c00
65 #define RT700_VERB_GET_CONNECT_SEL			0xb100
66 #define RT700_VERB_SET_POWER_STATE			0x3500
67 #define RT700_VERB_SET_CHANNEL_STREAMID			0x3600
68 #define RT700_VERB_SET_PIN_WIDGET_CONTROL		0x3700
69 #define RT700_VERB_SET_UNSOLICITED_ENABLE		0x3800
70 #define RT700_SET_AMP_GAIN_MUTE_H			0x7300
71 #define RT700_SET_AMP_GAIN_MUTE_L			0x8380
72 #define RT700_VERB_GET_PIN_SENSE			0xb900
73 
74 #define RT700_READ_HDA_3				0x2012
75 #define RT700_READ_HDA_2				0x2013
76 #define RT700_READ_HDA_1				0x2014
77 #define RT700_READ_HDA_0				0x2015
78 #define RT700_PRIV_INDEX_W_H				0x7520
79 #define RT700_PRIV_INDEX_W_L				0x85a0
80 #define RT700_PRIV_DATA_W_H				0x7420
81 #define RT700_PRIV_DATA_W_L				0x84a0
82 #define RT700_PRIV_INDEX_R_H				0x9d20
83 #define RT700_PRIV_INDEX_R_L				0xada0
84 #define RT700_PRIV_DATA_R_H				0x9c20
85 #define RT700_PRIV_DATA_R_L				0xaca0
86 #define RT700_DAC_FORMAT_H				0x7203
87 #define RT700_DAC_FORMAT_L				0x8283
88 #define RT700_ADC_FORMAT_H				0x7209
89 #define RT700_ADC_FORMAT_L				0x8289
90 #define RT700_SET_AUDIO_POWER_STATE\
91 	(RT700_VERB_SET_POWER_STATE | RT700_AUDIO_FUNCTION_GROUP)
92 #define RT700_SET_PIN_DMIC1\
93 	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_DMIC1)
94 #define RT700_SET_PIN_DMIC2\
95 	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_DMIC2)
96 #define RT700_SET_PIN_SPK\
97 	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_SPK_OUT)
98 #define RT700_SET_PIN_HP\
99 	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_HP_OUT)
100 #define RT700_SET_PIN_MIC2\
101 	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_MIC2)
102 #define RT700_SET_PIN_LINE1\
103 	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_LINE1)
104 #define RT700_SET_PIN_LINE2\
105 	(RT700_VERB_SET_PIN_WIDGET_CONTROL | RT700_LINE2)
106 #define RT700_SET_MIC2_UNSOLICITED_ENABLE\
107 	(RT700_VERB_SET_UNSOLICITED_ENABLE | RT700_MIC2)
108 #define RT700_SET_HP_UNSOLICITED_ENABLE\
109 	(RT700_VERB_SET_UNSOLICITED_ENABLE | RT700_HP_OUT)
110 #define RT700_SET_INLINE_UNSOLICITED_ENABLE\
111 	(RT700_VERB_SET_UNSOLICITED_ENABLE | RT700_INLINE_CMD)
112 #define RT700_SET_STREAMID_DAC1\
113 	(RT700_VERB_SET_CHANNEL_STREAMID | RT700_DAC_OUT1)
114 #define RT700_SET_STREAMID_DAC2\
115 	(RT700_VERB_SET_CHANNEL_STREAMID | RT700_DAC_OUT2)
116 #define RT700_SET_STREAMID_ADC1\
117 	(RT700_VERB_SET_CHANNEL_STREAMID | RT700_ADC_IN1)
118 #define RT700_SET_STREAMID_ADC2\
119 	(RT700_VERB_SET_CHANNEL_STREAMID | RT700_ADC_IN2)
120 #define RT700_SET_GAIN_DAC1_L\
121 	(RT700_SET_AMP_GAIN_MUTE_L | RT700_DAC_OUT1)
122 #define RT700_SET_GAIN_DAC1_H\
123 	(RT700_SET_AMP_GAIN_MUTE_H | RT700_DAC_OUT1)
124 #define RT700_SET_GAIN_ADC1_L\
125 	(RT700_SET_AMP_GAIN_MUTE_L | RT700_ADC_IN1)
126 #define RT700_SET_GAIN_ADC1_H\
127 	(RT700_SET_AMP_GAIN_MUTE_H | RT700_ADC_IN1)
128 #define RT700_SET_GAIN_ADC2_L\
129 	(RT700_SET_AMP_GAIN_MUTE_L | RT700_ADC_IN2)
130 #define RT700_SET_GAIN_ADC2_H\
131 	(RT700_SET_AMP_GAIN_MUTE_H | RT700_ADC_IN2)
132 #define RT700_SET_GAIN_AMIC_L\
133 	(RT700_SET_AMP_GAIN_MUTE_L | RT700_MIC2)
134 #define RT700_SET_GAIN_AMIC_H\
135 	(RT700_SET_AMP_GAIN_MUTE_H | RT700_MIC2)
136 #define RT700_SET_GAIN_HP_L\
137 	(RT700_SET_AMP_GAIN_MUTE_L | RT700_HP_OUT)
138 #define RT700_SET_GAIN_HP_H\
139 	(RT700_SET_AMP_GAIN_MUTE_H | RT700_HP_OUT)
140 #define RT700_SET_GAIN_SPK_L\
141 	(RT700_SET_AMP_GAIN_MUTE_L | RT700_SPK_OUT)
142 #define RT700_SET_GAIN_SPK_H\
143 	(RT700_SET_AMP_GAIN_MUTE_H | RT700_SPK_OUT)
144 #define RT700_SET_EAPD_SPK\
145 	(RT700_VERB_SET_EAPD_BTLENABLE | RT700_SPK_OUT)
146 
147 /* combo jack auto switch control 2 (0x46)(NID:20h) */
148 #define RT700_COMBOJACK_AUTO_DET_STATUS			(0x1 << 11)
149 #define RT700_COMBOJACK_AUTO_DET_TRS			(0x1 << 10)
150 #define RT700_COMBOJACK_AUTO_DET_CTIA			(0x1 << 9)
151 #define RT700_COMBOJACK_AUTO_DET_OMTP			(0x1 << 8)
152 
153 #define RT700_EAPD_HIGH					0x2
154 #define RT700_EAPD_LOW					0x0
155 #define RT700_MUTE_SFT					7
156 #define RT700_DIR_IN_SFT				6
157 #define RT700_DIR_OUT_SFT				7
158 
159 enum {
160 	RT700_AIF1,
161 	RT700_AIF2,
162 	RT700_AIFS,
163 };
164 
165 int rt700_io_init(struct device *dev, struct sdw_slave *slave);
166 int rt700_init(struct device *dev, struct regmap *sdw_regmap,
167 	       struct regmap *regmap, struct sdw_slave *slave);
168 
169 int rt700_jack_detect(struct rt700_priv *rt700, bool *hp, bool *mic);
170 int rt700_clock_config(struct device *dev);
171 #endif /* __RT700_H__ */
172