blob: e7a82565b905eca4616ea4da53d23ece3ee94a0f [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Bard Liao997b0522013-06-11 13:10:16 +08002/*
Oder Chioub0c27842014-04-10 10:57:34 +08003 * rt5640.c -- RT5640/RT5639 ALSA SoC audio codec driver
Bard Liao997b0522013-06-11 13:10:16 +08004 *
5 * Copyright 2011 Realtek Semiconductor Corp.
6 * Author: Johnny Hsu <johnnyhsu@realtek.com>
7 * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
Bard Liao997b0522013-06-11 13:10:16 +08008 */
9
10#include <linux/module.h>
11#include <linux/moduleparam.h>
12#include <linux/init.h>
13#include <linux/delay.h>
14#include <linux/pm.h>
15#include <linux/gpio.h>
16#include <linux/i2c.h>
17#include <linux/regmap.h>
Sachin Kamataffb74a2014-04-04 11:29:11 +053018#include <linux/of.h>
Stephen Warrendcad9f02013-06-12 11:34:30 -060019#include <linux/of_gpio.h>
Bard Liao997b0522013-06-11 13:10:16 +080020#include <linux/platform_device.h>
21#include <linux/spi/spi.h>
Liam Girdwood02b80772013-09-13 17:57:36 +010022#include <linux/acpi.h>
Bard Liao997b0522013-06-11 13:10:16 +080023#include <sound/core.h>
Hans de Goede82108042018-05-08 17:35:51 +020024#include <sound/jack.h>
Bard Liao997b0522013-06-11 13:10:16 +080025#include <sound/pcm.h>
26#include <sound/pcm_params.h>
27#include <sound/soc.h>
28#include <sound/soc-dapm.h>
29#include <sound/initval.h>
30#include <sound/tlv.h>
31
Oder Chiou49ef7922014-05-20 15:01:53 +080032#include "rl6231.h"
Bard Liao997b0522013-06-11 13:10:16 +080033#include "rt5640.h"
34
35#define RT5640_DEVICE_ID 0x6231
36
37#define RT5640_PR_RANGE_BASE (0xff + 1)
38#define RT5640_PR_SPACING 0x100
39
40#define RT5640_PR_BASE (RT5640_PR_RANGE_BASE + (0 * RT5640_PR_SPACING))
41
42static const struct regmap_range_cfg rt5640_ranges[] = {
43 { .name = "PR", .range_min = RT5640_PR_BASE,
44 .range_max = RT5640_PR_BASE + 0xb4,
45 .selector_reg = RT5640_PRIV_INDEX,
46 .selector_mask = 0xff,
47 .selector_shift = 0x0,
48 .window_start = RT5640_PRIV_DATA,
49 .window_len = 0x1, },
50};
51
Nariman Poushin8019ff62015-07-16 16:36:21 +010052static const struct reg_sequence init_list[] = {
Bard Liao997b0522013-06-11 13:10:16 +080053 {RT5640_PR_BASE + 0x3d, 0x3600},
Bard Liao997b0522013-06-11 13:10:16 +080054 {RT5640_PR_BASE + 0x12, 0x0aa8},
55 {RT5640_PR_BASE + 0x14, 0x0aaa},
56 {RT5640_PR_BASE + 0x20, 0x6110},
57 {RT5640_PR_BASE + 0x21, 0xe0e0},
58 {RT5640_PR_BASE + 0x23, 0x1804},
59};
Bard Liao997b0522013-06-11 13:10:16 +080060
Oder Chiou2f2a7142014-03-28 20:28:25 +080061static const struct reg_default rt5640_reg[] = {
Bard Liao997b0522013-06-11 13:10:16 +080062 { 0x00, 0x000e },
63 { 0x01, 0xc8c8 },
64 { 0x02, 0xc8c8 },
65 { 0x03, 0xc8c8 },
66 { 0x04, 0x8000 },
67 { 0x0d, 0x0000 },
68 { 0x0e, 0x0000 },
69 { 0x0f, 0x0808 },
70 { 0x19, 0xafaf },
71 { 0x1a, 0xafaf },
72 { 0x1b, 0x0000 },
73 { 0x1c, 0x2f2f },
74 { 0x1d, 0x2f2f },
75 { 0x1e, 0x0000 },
76 { 0x27, 0x7060 },
77 { 0x28, 0x7070 },
78 { 0x29, 0x8080 },
79 { 0x2a, 0x5454 },
80 { 0x2b, 0x5454 },
81 { 0x2c, 0xaa00 },
82 { 0x2d, 0x0000 },
83 { 0x2e, 0xa000 },
84 { 0x2f, 0x0000 },
85 { 0x3b, 0x0000 },
86 { 0x3c, 0x007f },
87 { 0x3d, 0x0000 },
88 { 0x3e, 0x007f },
89 { 0x45, 0xe000 },
90 { 0x46, 0x003e },
91 { 0x47, 0x003e },
92 { 0x48, 0xf800 },
93 { 0x49, 0x3800 },
94 { 0x4a, 0x0004 },
95 { 0x4c, 0xfc00 },
96 { 0x4d, 0x0000 },
97 { 0x4f, 0x01ff },
98 { 0x50, 0x0000 },
99 { 0x51, 0x0000 },
100 { 0x52, 0x01ff },
101 { 0x53, 0xf000 },
102 { 0x61, 0x0000 },
103 { 0x62, 0x0000 },
104 { 0x63, 0x00c0 },
105 { 0x64, 0x0000 },
106 { 0x65, 0x0000 },
107 { 0x66, 0x0000 },
108 { 0x6a, 0x0000 },
109 { 0x6c, 0x0000 },
110 { 0x70, 0x8000 },
111 { 0x71, 0x8000 },
112 { 0x72, 0x8000 },
113 { 0x73, 0x1114 },
114 { 0x74, 0x0c00 },
115 { 0x75, 0x1d00 },
116 { 0x80, 0x0000 },
117 { 0x81, 0x0000 },
118 { 0x82, 0x0000 },
119 { 0x83, 0x0000 },
120 { 0x84, 0x0000 },
121 { 0x85, 0x0008 },
122 { 0x89, 0x0000 },
123 { 0x8a, 0x0000 },
124 { 0x8b, 0x0600 },
125 { 0x8c, 0x0228 },
126 { 0x8d, 0xa000 },
127 { 0x8e, 0x0004 },
128 { 0x8f, 0x1100 },
129 { 0x90, 0x0646 },
130 { 0x91, 0x0c00 },
131 { 0x92, 0x0000 },
132 { 0x93, 0x3000 },
133 { 0xb0, 0x2080 },
134 { 0xb1, 0x0000 },
135 { 0xb4, 0x2206 },
136 { 0xb5, 0x1f00 },
137 { 0xb6, 0x0000 },
138 { 0xb8, 0x034b },
139 { 0xb9, 0x0066 },
140 { 0xba, 0x000b },
141 { 0xbb, 0x0000 },
142 { 0xbc, 0x0000 },
143 { 0xbd, 0x0000 },
144 { 0xbe, 0x0000 },
145 { 0xbf, 0x0000 },
146 { 0xc0, 0x0400 },
147 { 0xc2, 0x0000 },
148 { 0xc4, 0x0000 },
149 { 0xc5, 0x0000 },
150 { 0xc6, 0x2000 },
151 { 0xc8, 0x0000 },
152 { 0xc9, 0x0000 },
153 { 0xca, 0x0000 },
154 { 0xcb, 0x0000 },
155 { 0xcc, 0x0000 },
156 { 0xcf, 0x0013 },
157 { 0xd0, 0x0680 },
158 { 0xd1, 0x1c17 },
159 { 0xd2, 0x8c00 },
160 { 0xd3, 0xaa20 },
161 { 0xd6, 0x0400 },
162 { 0xd9, 0x0809 },
163 { 0xfe, 0x10ec },
164 { 0xff, 0x6231 },
165};
166
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000167static int rt5640_reset(struct snd_soc_component *component)
Bard Liao997b0522013-06-11 13:10:16 +0800168{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000169 return snd_soc_component_write(component, RT5640_RESET, 0);
Bard Liao997b0522013-06-11 13:10:16 +0800170}
171
172static bool rt5640_volatile_register(struct device *dev, unsigned int reg)
173{
174 int i;
175
176 for (i = 0; i < ARRAY_SIZE(rt5640_ranges); i++)
177 if ((reg >= rt5640_ranges[i].window_start &&
178 reg <= rt5640_ranges[i].window_start +
179 rt5640_ranges[i].window_len) ||
180 (reg >= rt5640_ranges[i].range_min &&
181 reg <= rt5640_ranges[i].range_max))
182 return true;
183
184 switch (reg) {
185 case RT5640_RESET:
186 case RT5640_ASRC_5:
187 case RT5640_EQ_CTRL1:
188 case RT5640_DRC_AGC_1:
189 case RT5640_ANC_CTRL1:
190 case RT5640_IRQ_CTRL2:
191 case RT5640_INT_IRQ_ST:
192 case RT5640_DSP_CTRL2:
193 case RT5640_DSP_CTRL3:
194 case RT5640_PRIV_INDEX:
195 case RT5640_PRIV_DATA:
196 case RT5640_PGM_REG_ARR1:
197 case RT5640_PGM_REG_ARR3:
Oder Chiou2b9c8d22021-11-25 13:58:12 +0800198 case RT5640_DUMMY2:
Bard Liao997b0522013-06-11 13:10:16 +0800199 case RT5640_VENDOR_ID:
200 case RT5640_VENDOR_ID1:
201 case RT5640_VENDOR_ID2:
202 return true;
203 default:
204 return false;
205 }
206}
207
208static bool rt5640_readable_register(struct device *dev, unsigned int reg)
209{
210 int i;
211
212 for (i = 0; i < ARRAY_SIZE(rt5640_ranges); i++)
213 if ((reg >= rt5640_ranges[i].window_start &&
214 reg <= rt5640_ranges[i].window_start +
215 rt5640_ranges[i].window_len) ||
216 (reg >= rt5640_ranges[i].range_min &&
217 reg <= rt5640_ranges[i].range_max))
218 return true;
219
220 switch (reg) {
221 case RT5640_RESET:
222 case RT5640_SPK_VOL:
223 case RT5640_HP_VOL:
224 case RT5640_OUTPUT:
225 case RT5640_MONO_OUT:
226 case RT5640_IN1_IN2:
227 case RT5640_IN3_IN4:
228 case RT5640_INL_INR_VOL:
229 case RT5640_DAC1_DIG_VOL:
230 case RT5640_DAC2_DIG_VOL:
231 case RT5640_DAC2_CTRL:
232 case RT5640_ADC_DIG_VOL:
233 case RT5640_ADC_DATA:
234 case RT5640_ADC_BST_VOL:
235 case RT5640_STO_ADC_MIXER:
236 case RT5640_MONO_ADC_MIXER:
237 case RT5640_AD_DA_MIXER:
238 case RT5640_STO_DAC_MIXER:
239 case RT5640_MONO_DAC_MIXER:
240 case RT5640_DIG_MIXER:
241 case RT5640_DSP_PATH1:
242 case RT5640_DSP_PATH2:
243 case RT5640_DIG_INF_DATA:
244 case RT5640_REC_L1_MIXER:
245 case RT5640_REC_L2_MIXER:
246 case RT5640_REC_R1_MIXER:
247 case RT5640_REC_R2_MIXER:
248 case RT5640_HPO_MIXER:
249 case RT5640_SPK_L_MIXER:
250 case RT5640_SPK_R_MIXER:
251 case RT5640_SPO_L_MIXER:
252 case RT5640_SPO_R_MIXER:
253 case RT5640_SPO_CLSD_RATIO:
254 case RT5640_MONO_MIXER:
255 case RT5640_OUT_L1_MIXER:
256 case RT5640_OUT_L2_MIXER:
257 case RT5640_OUT_L3_MIXER:
258 case RT5640_OUT_R1_MIXER:
259 case RT5640_OUT_R2_MIXER:
260 case RT5640_OUT_R3_MIXER:
261 case RT5640_LOUT_MIXER:
262 case RT5640_PWR_DIG1:
263 case RT5640_PWR_DIG2:
264 case RT5640_PWR_ANLG1:
265 case RT5640_PWR_ANLG2:
266 case RT5640_PWR_MIXER:
267 case RT5640_PWR_VOL:
268 case RT5640_PRIV_INDEX:
269 case RT5640_PRIV_DATA:
270 case RT5640_I2S1_SDP:
271 case RT5640_I2S2_SDP:
272 case RT5640_ADDA_CLK1:
273 case RT5640_ADDA_CLK2:
274 case RT5640_DMIC:
275 case RT5640_GLB_CLK:
276 case RT5640_PLL_CTRL1:
277 case RT5640_PLL_CTRL2:
278 case RT5640_ASRC_1:
279 case RT5640_ASRC_2:
280 case RT5640_ASRC_3:
281 case RT5640_ASRC_4:
282 case RT5640_ASRC_5:
283 case RT5640_HP_OVCD:
284 case RT5640_CLS_D_OVCD:
285 case RT5640_CLS_D_OUT:
286 case RT5640_DEPOP_M1:
287 case RT5640_DEPOP_M2:
288 case RT5640_DEPOP_M3:
289 case RT5640_CHARGE_PUMP:
290 case RT5640_PV_DET_SPK_G:
291 case RT5640_MICBIAS:
292 case RT5640_EQ_CTRL1:
293 case RT5640_EQ_CTRL2:
294 case RT5640_WIND_FILTER:
295 case RT5640_DRC_AGC_1:
296 case RT5640_DRC_AGC_2:
297 case RT5640_DRC_AGC_3:
298 case RT5640_SVOL_ZC:
299 case RT5640_ANC_CTRL1:
300 case RT5640_ANC_CTRL2:
301 case RT5640_ANC_CTRL3:
302 case RT5640_JD_CTRL:
303 case RT5640_ANC_JD:
304 case RT5640_IRQ_CTRL1:
305 case RT5640_IRQ_CTRL2:
306 case RT5640_INT_IRQ_ST:
307 case RT5640_GPIO_CTRL1:
308 case RT5640_GPIO_CTRL2:
309 case RT5640_GPIO_CTRL3:
310 case RT5640_DSP_CTRL1:
311 case RT5640_DSP_CTRL2:
312 case RT5640_DSP_CTRL3:
313 case RT5640_DSP_CTRL4:
314 case RT5640_PGM_REG_ARR1:
315 case RT5640_PGM_REG_ARR2:
316 case RT5640_PGM_REG_ARR3:
317 case RT5640_PGM_REG_ARR4:
318 case RT5640_PGM_REG_ARR5:
319 case RT5640_SCB_FUNC:
320 case RT5640_SCB_CTRL:
321 case RT5640_BASE_BACK:
322 case RT5640_MP3_PLUS1:
323 case RT5640_MP3_PLUS2:
324 case RT5640_3D_HP:
325 case RT5640_ADJ_HPF:
326 case RT5640_HP_CALIB_AMP_DET:
327 case RT5640_HP_CALIB2:
328 case RT5640_SV_ZCD1:
329 case RT5640_SV_ZCD2:
330 case RT5640_DUMMY1:
331 case RT5640_DUMMY2:
332 case RT5640_DUMMY3:
333 case RT5640_VENDOR_ID:
334 case RT5640_VENDOR_ID1:
335 case RT5640_VENDOR_ID2:
336 return true;
337 default:
338 return false;
339 }
340}
341
342static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
Hans de Goedecfa26ed2021-02-26 15:38:13 +0100343static const DECLARE_TLV_DB_MINMAX(dac_vol_tlv, -6562, 0);
Bard Liao997b0522013-06-11 13:10:16 +0800344static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
Hans de Goedecfa26ed2021-02-26 15:38:13 +0100345static const DECLARE_TLV_DB_MINMAX(adc_vol_tlv, -1762, 3000);
Bard Liao997b0522013-06-11 13:10:16 +0800346static const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0);
347
348/* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
Lars-Peter Clausen82958222015-08-02 17:19:48 +0200349static const DECLARE_TLV_DB_RANGE(bst_tlv,
Bard Liao997b0522013-06-11 13:10:16 +0800350 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
351 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
352 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
353 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
354 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
355 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
Lars-Peter Clausen82958222015-08-02 17:19:48 +0200356 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0)
357);
Bard Liao997b0522013-06-11 13:10:16 +0800358
359/* Interface data select */
360static const char * const rt5640_data_select[] = {
Sugar Zhang653aa462016-03-18 14:54:22 +0800361 "Normal", "Swap", "left copy to right", "right copy to left"};
Bard Liao997b0522013-06-11 13:10:16 +0800362
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100363static SOC_ENUM_SINGLE_DECL(rt5640_if1_dac_enum, RT5640_DIG_INF_DATA,
364 RT5640_IF1_DAC_SEL_SFT, rt5640_data_select);
Bard Liao997b0522013-06-11 13:10:16 +0800365
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100366static SOC_ENUM_SINGLE_DECL(rt5640_if1_adc_enum, RT5640_DIG_INF_DATA,
367 RT5640_IF1_ADC_SEL_SFT, rt5640_data_select);
Bard Liao997b0522013-06-11 13:10:16 +0800368
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100369static SOC_ENUM_SINGLE_DECL(rt5640_if2_dac_enum, RT5640_DIG_INF_DATA,
370 RT5640_IF2_DAC_SEL_SFT, rt5640_data_select);
Bard Liao997b0522013-06-11 13:10:16 +0800371
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100372static SOC_ENUM_SINGLE_DECL(rt5640_if2_adc_enum, RT5640_DIG_INF_DATA,
373 RT5640_IF2_ADC_SEL_SFT, rt5640_data_select);
Bard Liao997b0522013-06-11 13:10:16 +0800374
375/* Class D speaker gain ratio */
376static const char * const rt5640_clsd_spk_ratio[] = {"1.66x", "1.83x", "1.94x",
377 "2x", "2.11x", "2.22x", "2.33x", "2.44x", "2.55x", "2.66x", "2.77x"};
378
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100379static SOC_ENUM_SINGLE_DECL(rt5640_clsd_spk_ratio_enum, RT5640_CLS_D_OUT,
380 RT5640_CLSD_RATIO_SFT, rt5640_clsd_spk_ratio);
Bard Liao997b0522013-06-11 13:10:16 +0800381
382static const struct snd_kcontrol_new rt5640_snd_controls[] = {
383 /* Speaker Output Volume */
Bard Liao997b0522013-06-11 13:10:16 +0800384 SOC_DOUBLE("Speaker Channel Switch", RT5640_SPK_VOL,
385 RT5640_VOL_L_SFT, RT5640_VOL_R_SFT, 1, 1),
386 SOC_DOUBLE_TLV("Speaker Playback Volume", RT5640_SPK_VOL,
387 RT5640_L_VOL_SFT, RT5640_R_VOL_SFT, 39, 1, out_vol_tlv),
388 /* Headphone Output Volume */
Bard Liao997b0522013-06-11 13:10:16 +0800389 SOC_DOUBLE("HP Channel Switch", RT5640_HP_VOL,
390 RT5640_VOL_L_SFT, RT5640_VOL_R_SFT, 1, 1),
391 SOC_DOUBLE_TLV("HP Playback Volume", RT5640_HP_VOL,
392 RT5640_L_VOL_SFT, RT5640_R_VOL_SFT, 39, 1, out_vol_tlv),
393 /* OUTPUT Control */
394 SOC_DOUBLE("OUT Playback Switch", RT5640_OUTPUT,
395 RT5640_L_MUTE_SFT, RT5640_R_MUTE_SFT, 1, 1),
396 SOC_DOUBLE("OUT Channel Switch", RT5640_OUTPUT,
397 RT5640_VOL_L_SFT, RT5640_VOL_R_SFT, 1, 1),
398 SOC_DOUBLE_TLV("OUT Playback Volume", RT5640_OUTPUT,
399 RT5640_L_VOL_SFT, RT5640_R_VOL_SFT, 39, 1, out_vol_tlv),
Oder Chiou022d21f2014-04-08 19:40:00 +0800400
Bard Liao997b0522013-06-11 13:10:16 +0800401 /* DAC Digital Volume */
402 SOC_DOUBLE("DAC2 Playback Switch", RT5640_DAC2_CTRL,
403 RT5640_M_DAC_L2_VOL_SFT, RT5640_M_DAC_R2_VOL_SFT, 1, 1),
Hans de Goede40e40462021-03-07 16:05:02 +0100404 SOC_DOUBLE_TLV("DAC2 Playback Volume", RT5640_DAC2_DIG_VOL,
405 RT5640_L_VOL_SFT, RT5640_R_VOL_SFT,
406 175, 0, dac_vol_tlv),
Bard Liao997b0522013-06-11 13:10:16 +0800407 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5640_DAC1_DIG_VOL,
408 RT5640_L_VOL_SFT, RT5640_R_VOL_SFT,
409 175, 0, dac_vol_tlv),
Oder Chiou16566e42015-10-21 09:46:05 +0800410 /* IN1/IN2/IN3 Control */
Bard Liao997b0522013-06-11 13:10:16 +0800411 SOC_SINGLE_TLV("IN1 Boost", RT5640_IN1_IN2,
412 RT5640_BST_SFT1, 8, 0, bst_tlv),
413 SOC_SINGLE_TLV("IN2 Boost", RT5640_IN3_IN4,
414 RT5640_BST_SFT2, 8, 0, bst_tlv),
Oder Chiou16566e42015-10-21 09:46:05 +0800415 SOC_SINGLE_TLV("IN3 Boost", RT5640_IN1_IN2,
416 RT5640_BST_SFT2, 8, 0, bst_tlv),
417
Bard Liao997b0522013-06-11 13:10:16 +0800418 /* INL/INR Volume Control */
419 SOC_DOUBLE_TLV("IN Capture Volume", RT5640_INL_INR_VOL,
420 RT5640_INL_VOL_SFT, RT5640_INR_VOL_SFT,
421 31, 1, in_vol_tlv),
422 /* ADC Digital Volume Control */
423 SOC_DOUBLE("ADC Capture Switch", RT5640_ADC_DIG_VOL,
424 RT5640_L_MUTE_SFT, RT5640_R_MUTE_SFT, 1, 1),
425 SOC_DOUBLE_TLV("ADC Capture Volume", RT5640_ADC_DIG_VOL,
426 RT5640_L_VOL_SFT, RT5640_R_VOL_SFT,
427 127, 0, adc_vol_tlv),
Bard Liaoca5f17c2016-10-26 09:40:44 +0800428 SOC_DOUBLE("Mono ADC Capture Switch", RT5640_DUMMY1,
429 RT5640_M_MONO_ADC_L_SFT, RT5640_M_MONO_ADC_R_SFT, 1, 1),
Bard Liao997b0522013-06-11 13:10:16 +0800430 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5640_ADC_DATA,
431 RT5640_L_VOL_SFT, RT5640_R_VOL_SFT,
432 127, 0, adc_vol_tlv),
433 /* ADC Boost Volume Control */
434 SOC_DOUBLE_TLV("ADC Boost Gain", RT5640_ADC_BST_VOL,
435 RT5640_ADC_L_BST_SFT, RT5640_ADC_R_BST_SFT,
436 3, 0, adc_bst_tlv),
437 /* Class D speaker gain ratio */
438 SOC_ENUM("Class D SPK Ratio Control", rt5640_clsd_spk_ratio_enum),
439
440 SOC_ENUM("ADC IF1 Data Switch", rt5640_if1_adc_enum),
441 SOC_ENUM("DAC IF1 Data Switch", rt5640_if1_dac_enum),
442 SOC_ENUM("ADC IF2 Data Switch", rt5640_if2_adc_enum),
443 SOC_ENUM("DAC IF2 Data Switch", rt5640_if2_dac_enum),
444};
445
Oder Chiou022d21f2014-04-08 19:40:00 +0800446static const struct snd_kcontrol_new rt5640_specific_snd_controls[] = {
447 /* MONO Output Control */
448 SOC_SINGLE("Mono Playback Switch", RT5640_MONO_OUT, RT5640_L_MUTE_SFT,
449 1, 1),
Oder Chiou022d21f2014-04-08 19:40:00 +0800450};
451
Bard Liao997b0522013-06-11 13:10:16 +0800452/**
453 * set_dmic_clk - Set parameter of dmic.
454 *
455 * @w: DAPM widget.
456 * @kcontrol: The kcontrol of this widget.
457 * @event: Event id.
458 *
Bard Liao997b0522013-06-11 13:10:16 +0800459 */
460static int set_dmic_clk(struct snd_soc_dapm_widget *w,
461 struct snd_kcontrol *kcontrol, int event)
462{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000463 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
464 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Oder Chiou00a6d6e52015-08-05 10:03:18 +0800465 int idx, rate;
Bard Liao997b0522013-06-11 13:10:16 +0800466
Oder Chiou00a6d6e52015-08-05 10:03:18 +0800467 rate = rt5640->sysclk / rl6231_get_pre_div(rt5640->regmap,
468 RT5640_ADDA_CLK1, RT5640_I2S_PD1_SFT);
469 idx = rl6231_calc_dmic_clk(rate);
Bard Liao997b0522013-06-11 13:10:16 +0800470 if (idx < 0)
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000471 dev_err(component->dev, "Failed to set DMIC clock\n");
Bard Liao997b0522013-06-11 13:10:16 +0800472 else
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000473 snd_soc_component_update_bits(component, RT5640_DMIC, RT5640_DMIC_CLK_MASK,
Bard Liao997b0522013-06-11 13:10:16 +0800474 idx << RT5640_DMIC_CLK_SFT);
475 return idx;
476}
477
Jack Yubee3e022016-01-04 17:20:26 -0600478static int is_using_asrc(struct snd_soc_dapm_widget *source,
479 struct snd_soc_dapm_widget *sink)
480{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000481 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
482 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Jack Yubee3e022016-01-04 17:20:26 -0600483
484 if (!rt5640->asrc_en)
485 return 0;
486
487 return 1;
488}
489
Bard Liao997b0522013-06-11 13:10:16 +0800490/* Digital Mixer */
491static const struct snd_kcontrol_new rt5640_sto_adc_l_mix[] = {
492 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_STO_ADC_MIXER,
493 RT5640_M_ADC_L1_SFT, 1, 1),
494 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_STO_ADC_MIXER,
495 RT5640_M_ADC_L2_SFT, 1, 1),
496};
497
498static const struct snd_kcontrol_new rt5640_sto_adc_r_mix[] = {
499 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_STO_ADC_MIXER,
500 RT5640_M_ADC_R1_SFT, 1, 1),
501 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_STO_ADC_MIXER,
502 RT5640_M_ADC_R2_SFT, 1, 1),
503};
504
505static const struct snd_kcontrol_new rt5640_mono_adc_l_mix[] = {
506 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_MONO_ADC_MIXER,
507 RT5640_M_MONO_ADC_L1_SFT, 1, 1),
508 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_MONO_ADC_MIXER,
509 RT5640_M_MONO_ADC_L2_SFT, 1, 1),
510};
511
512static const struct snd_kcontrol_new rt5640_mono_adc_r_mix[] = {
513 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_MONO_ADC_MIXER,
514 RT5640_M_MONO_ADC_R1_SFT, 1, 1),
515 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_MONO_ADC_MIXER,
516 RT5640_M_MONO_ADC_R2_SFT, 1, 1),
517};
518
519static const struct snd_kcontrol_new rt5640_dac_l_mix[] = {
520 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5640_AD_DA_MIXER,
521 RT5640_M_ADCMIX_L_SFT, 1, 1),
522 SOC_DAPM_SINGLE("INF1 Switch", RT5640_AD_DA_MIXER,
523 RT5640_M_IF1_DAC_L_SFT, 1, 1),
524};
525
526static const struct snd_kcontrol_new rt5640_dac_r_mix[] = {
527 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5640_AD_DA_MIXER,
528 RT5640_M_ADCMIX_R_SFT, 1, 1),
529 SOC_DAPM_SINGLE("INF1 Switch", RT5640_AD_DA_MIXER,
530 RT5640_M_IF1_DAC_R_SFT, 1, 1),
531};
532
533static const struct snd_kcontrol_new rt5640_sto_dac_l_mix[] = {
534 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_STO_DAC_MIXER,
535 RT5640_M_DAC_L1_SFT, 1, 1),
536 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_STO_DAC_MIXER,
537 RT5640_M_DAC_L2_SFT, 1, 1),
538 SOC_DAPM_SINGLE("ANC Switch", RT5640_STO_DAC_MIXER,
539 RT5640_M_ANC_DAC_L_SFT, 1, 1),
540};
541
542static const struct snd_kcontrol_new rt5640_sto_dac_r_mix[] = {
543 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_STO_DAC_MIXER,
544 RT5640_M_DAC_R1_SFT, 1, 1),
545 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_STO_DAC_MIXER,
546 RT5640_M_DAC_R2_SFT, 1, 1),
547 SOC_DAPM_SINGLE("ANC Switch", RT5640_STO_DAC_MIXER,
548 RT5640_M_ANC_DAC_R_SFT, 1, 1),
549};
550
Oder Chiou022d21f2014-04-08 19:40:00 +0800551static const struct snd_kcontrol_new rt5639_sto_dac_l_mix[] = {
552 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_STO_DAC_MIXER,
553 RT5640_M_DAC_L1_SFT, 1, 1),
554 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_STO_DAC_MIXER,
555 RT5640_M_DAC_L2_SFT, 1, 1),
556};
557
558static const struct snd_kcontrol_new rt5639_sto_dac_r_mix[] = {
559 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_STO_DAC_MIXER,
560 RT5640_M_DAC_R1_SFT, 1, 1),
561 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_STO_DAC_MIXER,
562 RT5640_M_DAC_R2_SFT, 1, 1),
563};
564
Bard Liao997b0522013-06-11 13:10:16 +0800565static const struct snd_kcontrol_new rt5640_mono_dac_l_mix[] = {
566 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_MONO_DAC_MIXER,
567 RT5640_M_DAC_L1_MONO_L_SFT, 1, 1),
568 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_MONO_DAC_MIXER,
569 RT5640_M_DAC_L2_MONO_L_SFT, 1, 1),
570 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_MONO_DAC_MIXER,
571 RT5640_M_DAC_R2_MONO_L_SFT, 1, 1),
572};
573
574static const struct snd_kcontrol_new rt5640_mono_dac_r_mix[] = {
575 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_MONO_DAC_MIXER,
576 RT5640_M_DAC_R1_MONO_R_SFT, 1, 1),
577 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_MONO_DAC_MIXER,
578 RT5640_M_DAC_R2_MONO_R_SFT, 1, 1),
579 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_MONO_DAC_MIXER,
580 RT5640_M_DAC_L2_MONO_R_SFT, 1, 1),
581};
582
583static const struct snd_kcontrol_new rt5640_dig_l_mix[] = {
584 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_DIG_MIXER,
585 RT5640_M_STO_L_DAC_L_SFT, 1, 1),
586 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_DIG_MIXER,
587 RT5640_M_DAC_L2_DAC_L_SFT, 1, 1),
588};
589
590static const struct snd_kcontrol_new rt5640_dig_r_mix[] = {
591 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_DIG_MIXER,
592 RT5640_M_STO_R_DAC_R_SFT, 1, 1),
593 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_DIG_MIXER,
594 RT5640_M_DAC_R2_DAC_R_SFT, 1, 1),
595};
596
597/* Analog Input Mixer */
598static const struct snd_kcontrol_new rt5640_rec_l_mix[] = {
599 SOC_DAPM_SINGLE("HPOL Switch", RT5640_REC_L2_MIXER,
600 RT5640_M_HP_L_RM_L_SFT, 1, 1),
601 SOC_DAPM_SINGLE("INL Switch", RT5640_REC_L2_MIXER,
602 RT5640_M_IN_L_RM_L_SFT, 1, 1),
Oder Chiou16566e42015-10-21 09:46:05 +0800603 SOC_DAPM_SINGLE("BST3 Switch", RT5640_REC_L2_MIXER,
604 RT5640_M_BST2_RM_L_SFT, 1, 1),
Bard Liao997b0522013-06-11 13:10:16 +0800605 SOC_DAPM_SINGLE("BST2 Switch", RT5640_REC_L2_MIXER,
606 RT5640_M_BST4_RM_L_SFT, 1, 1),
607 SOC_DAPM_SINGLE("BST1 Switch", RT5640_REC_L2_MIXER,
608 RT5640_M_BST1_RM_L_SFT, 1, 1),
609 SOC_DAPM_SINGLE("OUT MIXL Switch", RT5640_REC_L2_MIXER,
610 RT5640_M_OM_L_RM_L_SFT, 1, 1),
611};
612
613static const struct snd_kcontrol_new rt5640_rec_r_mix[] = {
614 SOC_DAPM_SINGLE("HPOR Switch", RT5640_REC_R2_MIXER,
615 RT5640_M_HP_R_RM_R_SFT, 1, 1),
616 SOC_DAPM_SINGLE("INR Switch", RT5640_REC_R2_MIXER,
617 RT5640_M_IN_R_RM_R_SFT, 1, 1),
Oder Chiou16566e42015-10-21 09:46:05 +0800618 SOC_DAPM_SINGLE("BST3 Switch", RT5640_REC_R2_MIXER,
619 RT5640_M_BST2_RM_R_SFT, 1, 1),
Bard Liao997b0522013-06-11 13:10:16 +0800620 SOC_DAPM_SINGLE("BST2 Switch", RT5640_REC_R2_MIXER,
621 RT5640_M_BST4_RM_R_SFT, 1, 1),
622 SOC_DAPM_SINGLE("BST1 Switch", RT5640_REC_R2_MIXER,
623 RT5640_M_BST1_RM_R_SFT, 1, 1),
624 SOC_DAPM_SINGLE("OUT MIXR Switch", RT5640_REC_R2_MIXER,
625 RT5640_M_OM_R_RM_R_SFT, 1, 1),
626};
627
628/* Analog Output Mixer */
629static const struct snd_kcontrol_new rt5640_spk_l_mix[] = {
630 SOC_DAPM_SINGLE("REC MIXL Switch", RT5640_SPK_L_MIXER,
631 RT5640_M_RM_L_SM_L_SFT, 1, 1),
632 SOC_DAPM_SINGLE("INL Switch", RT5640_SPK_L_MIXER,
633 RT5640_M_IN_L_SM_L_SFT, 1, 1),
634 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_SPK_L_MIXER,
635 RT5640_M_DAC_L1_SM_L_SFT, 1, 1),
636 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_SPK_L_MIXER,
637 RT5640_M_DAC_L2_SM_L_SFT, 1, 1),
638 SOC_DAPM_SINGLE("OUT MIXL Switch", RT5640_SPK_L_MIXER,
639 RT5640_M_OM_L_SM_L_SFT, 1, 1),
640};
641
642static const struct snd_kcontrol_new rt5640_spk_r_mix[] = {
643 SOC_DAPM_SINGLE("REC MIXR Switch", RT5640_SPK_R_MIXER,
644 RT5640_M_RM_R_SM_R_SFT, 1, 1),
645 SOC_DAPM_SINGLE("INR Switch", RT5640_SPK_R_MIXER,
646 RT5640_M_IN_R_SM_R_SFT, 1, 1),
647 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_SPK_R_MIXER,
648 RT5640_M_DAC_R1_SM_R_SFT, 1, 1),
649 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_SPK_R_MIXER,
650 RT5640_M_DAC_R2_SM_R_SFT, 1, 1),
651 SOC_DAPM_SINGLE("OUT MIXR Switch", RT5640_SPK_R_MIXER,
652 RT5640_M_OM_R_SM_R_SFT, 1, 1),
653};
654
655static const struct snd_kcontrol_new rt5640_out_l_mix[] = {
656 SOC_DAPM_SINGLE("SPK MIXL Switch", RT5640_OUT_L3_MIXER,
657 RT5640_M_SM_L_OM_L_SFT, 1, 1),
658 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_L3_MIXER,
659 RT5640_M_BST1_OM_L_SFT, 1, 1),
660 SOC_DAPM_SINGLE("INL Switch", RT5640_OUT_L3_MIXER,
661 RT5640_M_IN_L_OM_L_SFT, 1, 1),
662 SOC_DAPM_SINGLE("REC MIXL Switch", RT5640_OUT_L3_MIXER,
663 RT5640_M_RM_L_OM_L_SFT, 1, 1),
664 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_OUT_L3_MIXER,
665 RT5640_M_DAC_R2_OM_L_SFT, 1, 1),
666 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_OUT_L3_MIXER,
667 RT5640_M_DAC_L2_OM_L_SFT, 1, 1),
668 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_OUT_L3_MIXER,
669 RT5640_M_DAC_L1_OM_L_SFT, 1, 1),
670};
671
672static const struct snd_kcontrol_new rt5640_out_r_mix[] = {
673 SOC_DAPM_SINGLE("SPK MIXR Switch", RT5640_OUT_R3_MIXER,
674 RT5640_M_SM_L_OM_R_SFT, 1, 1),
675 SOC_DAPM_SINGLE("BST2 Switch", RT5640_OUT_R3_MIXER,
676 RT5640_M_BST4_OM_R_SFT, 1, 1),
677 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_R3_MIXER,
678 RT5640_M_BST1_OM_R_SFT, 1, 1),
679 SOC_DAPM_SINGLE("INR Switch", RT5640_OUT_R3_MIXER,
680 RT5640_M_IN_R_OM_R_SFT, 1, 1),
681 SOC_DAPM_SINGLE("REC MIXR Switch", RT5640_OUT_R3_MIXER,
682 RT5640_M_RM_R_OM_R_SFT, 1, 1),
683 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_OUT_R3_MIXER,
684 RT5640_M_DAC_L2_OM_R_SFT, 1, 1),
685 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_OUT_R3_MIXER,
686 RT5640_M_DAC_R2_OM_R_SFT, 1, 1),
687 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_OUT_R3_MIXER,
688 RT5640_M_DAC_R1_OM_R_SFT, 1, 1),
689};
690
Oder Chiou022d21f2014-04-08 19:40:00 +0800691static const struct snd_kcontrol_new rt5639_out_l_mix[] = {
692 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_L3_MIXER,
693 RT5640_M_BST1_OM_L_SFT, 1, 1),
694 SOC_DAPM_SINGLE("INL Switch", RT5640_OUT_L3_MIXER,
695 RT5640_M_IN_L_OM_L_SFT, 1, 1),
696 SOC_DAPM_SINGLE("REC MIXL Switch", RT5640_OUT_L3_MIXER,
697 RT5640_M_RM_L_OM_L_SFT, 1, 1),
698 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_OUT_L3_MIXER,
699 RT5640_M_DAC_L1_OM_L_SFT, 1, 1),
700};
701
702static const struct snd_kcontrol_new rt5639_out_r_mix[] = {
703 SOC_DAPM_SINGLE("BST2 Switch", RT5640_OUT_R3_MIXER,
704 RT5640_M_BST4_OM_R_SFT, 1, 1),
705 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_R3_MIXER,
706 RT5640_M_BST1_OM_R_SFT, 1, 1),
707 SOC_DAPM_SINGLE("INR Switch", RT5640_OUT_R3_MIXER,
708 RT5640_M_IN_R_OM_R_SFT, 1, 1),
709 SOC_DAPM_SINGLE("REC MIXR Switch", RT5640_OUT_R3_MIXER,
710 RT5640_M_RM_R_OM_R_SFT, 1, 1),
711 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_OUT_R3_MIXER,
712 RT5640_M_DAC_R1_OM_R_SFT, 1, 1),
713};
714
Bard Liao997b0522013-06-11 13:10:16 +0800715static const struct snd_kcontrol_new rt5640_spo_l_mix[] = {
716 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_SPO_L_MIXER,
717 RT5640_M_DAC_R1_SPM_L_SFT, 1, 1),
718 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_SPO_L_MIXER,
719 RT5640_M_DAC_L1_SPM_L_SFT, 1, 1),
720 SOC_DAPM_SINGLE("SPKVOL R Switch", RT5640_SPO_L_MIXER,
721 RT5640_M_SV_R_SPM_L_SFT, 1, 1),
722 SOC_DAPM_SINGLE("SPKVOL L Switch", RT5640_SPO_L_MIXER,
723 RT5640_M_SV_L_SPM_L_SFT, 1, 1),
724 SOC_DAPM_SINGLE("BST1 Switch", RT5640_SPO_L_MIXER,
725 RT5640_M_BST1_SPM_L_SFT, 1, 1),
726};
727
728static const struct snd_kcontrol_new rt5640_spo_r_mix[] = {
729 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_SPO_R_MIXER,
730 RT5640_M_DAC_R1_SPM_R_SFT, 1, 1),
731 SOC_DAPM_SINGLE("SPKVOL R Switch", RT5640_SPO_R_MIXER,
732 RT5640_M_SV_R_SPM_R_SFT, 1, 1),
733 SOC_DAPM_SINGLE("BST1 Switch", RT5640_SPO_R_MIXER,
734 RT5640_M_BST1_SPM_R_SFT, 1, 1),
735};
736
737static const struct snd_kcontrol_new rt5640_hpo_mix[] = {
738 SOC_DAPM_SINGLE("HPO MIX DAC2 Switch", RT5640_HPO_MIXER,
739 RT5640_M_DAC2_HM_SFT, 1, 1),
740 SOC_DAPM_SINGLE("HPO MIX DAC1 Switch", RT5640_HPO_MIXER,
741 RT5640_M_DAC1_HM_SFT, 1, 1),
742 SOC_DAPM_SINGLE("HPO MIX HPVOL Switch", RT5640_HPO_MIXER,
743 RT5640_M_HPVOL_HM_SFT, 1, 1),
744};
745
Oder Chiou022d21f2014-04-08 19:40:00 +0800746static const struct snd_kcontrol_new rt5639_hpo_mix[] = {
747 SOC_DAPM_SINGLE("HPO MIX DAC1 Switch", RT5640_HPO_MIXER,
748 RT5640_M_DAC1_HM_SFT, 1, 1),
749 SOC_DAPM_SINGLE("HPO MIX HPVOL Switch", RT5640_HPO_MIXER,
750 RT5640_M_HPVOL_HM_SFT, 1, 1),
751};
752
Bard Liao997b0522013-06-11 13:10:16 +0800753static const struct snd_kcontrol_new rt5640_lout_mix[] = {
754 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_LOUT_MIXER,
755 RT5640_M_DAC_L1_LM_SFT, 1, 1),
756 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_LOUT_MIXER,
757 RT5640_M_DAC_R1_LM_SFT, 1, 1),
758 SOC_DAPM_SINGLE("OUTVOL L Switch", RT5640_LOUT_MIXER,
759 RT5640_M_OV_L_LM_SFT, 1, 1),
760 SOC_DAPM_SINGLE("OUTVOL R Switch", RT5640_LOUT_MIXER,
761 RT5640_M_OV_R_LM_SFT, 1, 1),
762};
763
764static const struct snd_kcontrol_new rt5640_mono_mix[] = {
765 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_MONO_MIXER,
766 RT5640_M_DAC_R2_MM_SFT, 1, 1),
767 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_MONO_MIXER,
768 RT5640_M_DAC_L2_MM_SFT, 1, 1),
769 SOC_DAPM_SINGLE("OUTVOL R Switch", RT5640_MONO_MIXER,
770 RT5640_M_OV_R_MM_SFT, 1, 1),
771 SOC_DAPM_SINGLE("OUTVOL L Switch", RT5640_MONO_MIXER,
772 RT5640_M_OV_L_MM_SFT, 1, 1),
773 SOC_DAPM_SINGLE("BST1 Switch", RT5640_MONO_MIXER,
774 RT5640_M_BST1_MM_SFT, 1, 1),
775};
776
Bard Liao246693b2013-08-23 10:29:26 +0800777static const struct snd_kcontrol_new spk_l_enable_control =
778 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_SPK_VOL,
779 RT5640_L_MUTE_SFT, 1, 1);
780
781static const struct snd_kcontrol_new spk_r_enable_control =
782 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_SPK_VOL,
783 RT5640_R_MUTE_SFT, 1, 1);
784
785static const struct snd_kcontrol_new hp_l_enable_control =
786 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_HP_VOL,
787 RT5640_L_MUTE_SFT, 1, 1);
788
789static const struct snd_kcontrol_new hp_r_enable_control =
790 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_HP_VOL,
791 RT5640_R_MUTE_SFT, 1, 1);
792
Bard Liao997b0522013-06-11 13:10:16 +0800793/* Stereo ADC source */
794static const char * const rt5640_stereo_adc1_src[] = {
795 "DIG MIX", "ADC"
796};
797
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100798static SOC_ENUM_SINGLE_DECL(rt5640_stereo_adc1_enum, RT5640_STO_ADC_MIXER,
799 RT5640_ADC_1_SRC_SFT, rt5640_stereo_adc1_src);
Bard Liao997b0522013-06-11 13:10:16 +0800800
801static const struct snd_kcontrol_new rt5640_sto_adc_1_mux =
802 SOC_DAPM_ENUM("Stereo ADC1 Mux", rt5640_stereo_adc1_enum);
803
804static const char * const rt5640_stereo_adc2_src[] = {
805 "DMIC1", "DMIC2", "DIG MIX"
806};
807
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100808static SOC_ENUM_SINGLE_DECL(rt5640_stereo_adc2_enum, RT5640_STO_ADC_MIXER,
809 RT5640_ADC_2_SRC_SFT, rt5640_stereo_adc2_src);
Bard Liao997b0522013-06-11 13:10:16 +0800810
811static const struct snd_kcontrol_new rt5640_sto_adc_2_mux =
812 SOC_DAPM_ENUM("Stereo ADC2 Mux", rt5640_stereo_adc2_enum);
813
814/* Mono ADC source */
815static const char * const rt5640_mono_adc_l1_src[] = {
816 "Mono DAC MIXL", "ADCL"
817};
818
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100819static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_l1_enum, RT5640_MONO_ADC_MIXER,
820 RT5640_MONO_ADC_L1_SRC_SFT, rt5640_mono_adc_l1_src);
Bard Liao997b0522013-06-11 13:10:16 +0800821
822static const struct snd_kcontrol_new rt5640_mono_adc_l1_mux =
823 SOC_DAPM_ENUM("Mono ADC1 left source", rt5640_mono_adc_l1_enum);
824
825static const char * const rt5640_mono_adc_l2_src[] = {
826 "DMIC L1", "DMIC L2", "Mono DAC MIXL"
827};
828
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100829static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_l2_enum, RT5640_MONO_ADC_MIXER,
830 RT5640_MONO_ADC_L2_SRC_SFT, rt5640_mono_adc_l2_src);
Bard Liao997b0522013-06-11 13:10:16 +0800831
832static const struct snd_kcontrol_new rt5640_mono_adc_l2_mux =
833 SOC_DAPM_ENUM("Mono ADC2 left source", rt5640_mono_adc_l2_enum);
834
835static const char * const rt5640_mono_adc_r1_src[] = {
836 "Mono DAC MIXR", "ADCR"
837};
838
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100839static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_r1_enum, RT5640_MONO_ADC_MIXER,
840 RT5640_MONO_ADC_R1_SRC_SFT, rt5640_mono_adc_r1_src);
Bard Liao997b0522013-06-11 13:10:16 +0800841
842static const struct snd_kcontrol_new rt5640_mono_adc_r1_mux =
843 SOC_DAPM_ENUM("Mono ADC1 right source", rt5640_mono_adc_r1_enum);
844
845static const char * const rt5640_mono_adc_r2_src[] = {
846 "DMIC R1", "DMIC R2", "Mono DAC MIXR"
847};
848
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100849static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_r2_enum, RT5640_MONO_ADC_MIXER,
850 RT5640_MONO_ADC_R2_SRC_SFT, rt5640_mono_adc_r2_src);
Bard Liao997b0522013-06-11 13:10:16 +0800851
852static const struct snd_kcontrol_new rt5640_mono_adc_r2_mux =
853 SOC_DAPM_ENUM("Mono ADC2 right source", rt5640_mono_adc_r2_enum);
854
855/* DAC2 channel source */
856static const char * const rt5640_dac_l2_src[] = {
857 "IF2", "Base L/R"
858};
859
860static int rt5640_dac_l2_values[] = {
861 0,
862 3,
863};
864
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100865static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dac_l2_enum,
866 RT5640_DSP_PATH2, RT5640_DAC_L2_SEL_SFT,
867 0x3, rt5640_dac_l2_src, rt5640_dac_l2_values);
Bard Liao997b0522013-06-11 13:10:16 +0800868
869static const struct snd_kcontrol_new rt5640_dac_l2_mux =
Lars-Peter Clausen712fb1c2014-04-14 21:31:02 +0200870 SOC_DAPM_ENUM("DAC2 left channel source", rt5640_dac_l2_enum);
Bard Liao997b0522013-06-11 13:10:16 +0800871
872static const char * const rt5640_dac_r2_src[] = {
873 "IF2",
874};
875
876static int rt5640_dac_r2_values[] = {
877 0,
878};
879
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100880static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dac_r2_enum,
881 RT5640_DSP_PATH2, RT5640_DAC_R2_SEL_SFT,
882 0x3, rt5640_dac_r2_src, rt5640_dac_r2_values);
Bard Liao997b0522013-06-11 13:10:16 +0800883
884static const struct snd_kcontrol_new rt5640_dac_r2_mux =
885 SOC_DAPM_ENUM("DAC2 right channel source", rt5640_dac_r2_enum);
886
887/* digital interface and iis interface map */
888static const char * const rt5640_dai_iis_map[] = {
889 "1:1|2:2", "1:2|2:1", "1:1|2:1", "1:2|2:2"
890};
891
892static int rt5640_dai_iis_map_values[] = {
893 0,
894 5,
895 6,
896 7,
897};
898
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100899static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dai_iis_map_enum,
900 RT5640_I2S1_SDP, RT5640_I2S_IF_SFT,
901 0x7, rt5640_dai_iis_map,
902 rt5640_dai_iis_map_values);
Bard Liao997b0522013-06-11 13:10:16 +0800903
904static const struct snd_kcontrol_new rt5640_dai_mux =
Lars-Peter Clausen712fb1c2014-04-14 21:31:02 +0200905 SOC_DAPM_ENUM("DAI select", rt5640_dai_iis_map_enum);
Bard Liao997b0522013-06-11 13:10:16 +0800906
907/* SDI select */
908static const char * const rt5640_sdi_sel[] = {
909 "IF1", "IF2"
910};
911
Takashi Iwai4c03cb62014-02-18 09:43:21 +0100912static SOC_ENUM_SINGLE_DECL(rt5640_sdi_sel_enum, RT5640_I2S2_SDP,
913 RT5640_I2S2_SDI_SFT, rt5640_sdi_sel);
Bard Liao997b0522013-06-11 13:10:16 +0800914
915static const struct snd_kcontrol_new rt5640_sdi_mux =
916 SOC_DAPM_ENUM("SDI select", rt5640_sdi_sel_enum);
917
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000918static void hp_amp_power_on(struct snd_soc_component *component)
Bard Liao246693b2013-08-23 10:29:26 +0800919{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000920 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Bard Liao246693b2013-08-23 10:29:26 +0800921
922 /* depop parameters */
923 regmap_update_bits(rt5640->regmap, RT5640_PR_BASE +
924 RT5640_CHPUMP_INT_REG1, 0x0700, 0x0200);
925 regmap_update_bits(rt5640->regmap, RT5640_DEPOP_M2,
926 RT5640_DEPOP_MASK, RT5640_DEPOP_MAN);
927 regmap_update_bits(rt5640->regmap, RT5640_DEPOP_M1,
928 RT5640_HP_CP_MASK | RT5640_HP_SG_MASK | RT5640_HP_CB_MASK,
929 RT5640_HP_CP_PU | RT5640_HP_SG_DIS | RT5640_HP_CB_PU);
930 regmap_write(rt5640->regmap, RT5640_PR_BASE + RT5640_HP_DCC_INT1,
931 0x9f00);
932 /* headphone amp power on */
933 regmap_update_bits(rt5640->regmap, RT5640_PWR_ANLG1,
934 RT5640_PWR_FV1 | RT5640_PWR_FV2, 0);
935 regmap_update_bits(rt5640->regmap, RT5640_PWR_ANLG1,
936 RT5640_PWR_HA,
937 RT5640_PWR_HA);
938 usleep_range(10000, 15000);
939 regmap_update_bits(rt5640->regmap, RT5640_PWR_ANLG1,
940 RT5640_PWR_FV1 | RT5640_PWR_FV2 ,
941 RT5640_PWR_FV1 | RT5640_PWR_FV2);
942}
943
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000944static void rt5640_pmu_depop(struct snd_soc_component *component)
Bard Liao246693b2013-08-23 10:29:26 +0800945{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000946 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Bard Liao246693b2013-08-23 10:29:26 +0800947
948 regmap_update_bits(rt5640->regmap, RT5640_DEPOP_M2,
949 RT5640_DEPOP_MASK | RT5640_DIG_DP_MASK,
950 RT5640_DEPOP_AUTO | RT5640_DIG_DP_EN);
951 regmap_update_bits(rt5640->regmap, RT5640_CHARGE_PUMP,
952 RT5640_PM_HP_MASK, RT5640_PM_HP_HV);
953
954 regmap_update_bits(rt5640->regmap, RT5640_DEPOP_M3,
955 RT5640_CP_FQ1_MASK | RT5640_CP_FQ2_MASK | RT5640_CP_FQ3_MASK,
956 (RT5640_CP_FQ_192_KHZ << RT5640_CP_FQ1_SFT) |
957 (RT5640_CP_FQ_12_KHZ << RT5640_CP_FQ2_SFT) |
958 (RT5640_CP_FQ_192_KHZ << RT5640_CP_FQ3_SFT));
959
960 regmap_write(rt5640->regmap, RT5640_PR_BASE +
961 RT5640_MAMP_INT_REG2, 0x1c00);
962 regmap_update_bits(rt5640->regmap, RT5640_DEPOP_M1,
963 RT5640_HP_CP_MASK | RT5640_HP_SG_MASK,
964 RT5640_HP_CP_PD | RT5640_HP_SG_EN);
965 regmap_update_bits(rt5640->regmap, RT5640_PR_BASE +
966 RT5640_CHPUMP_INT_REG1, 0x0700, 0x0400);
967}
968
969static int rt5640_hp_event(struct snd_soc_dapm_widget *w,
970 struct snd_kcontrol *kcontrol, int event)
971{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000972 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
973 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Bard Liao246693b2013-08-23 10:29:26 +0800974
975 switch (event) {
976 case SND_SOC_DAPM_POST_PMU:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000977 rt5640_pmu_depop(component);
Pierre-Louis Bossarte0a99922019-01-04 20:02:40 -0600978 rt5640->hp_mute = false;
Bard Liao246693b2013-08-23 10:29:26 +0800979 break;
980
981 case SND_SOC_DAPM_PRE_PMD:
Pierre-Louis Bossarte0a99922019-01-04 20:02:40 -0600982 rt5640->hp_mute = true;
Nicholas Mc Guire4a312c92017-01-12 13:09:41 +0100983 msleep(70);
Bard Liao246693b2013-08-23 10:29:26 +0800984 break;
985
986 default:
987 return 0;
988 }
989
990 return 0;
991}
992
John Lin9b850ca2015-08-11 14:27:25 +0800993static int rt5640_lout_event(struct snd_soc_dapm_widget *w,
994 struct snd_kcontrol *kcontrol, int event)
995{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000996 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
John Lin9b850ca2015-08-11 14:27:25 +0800997
998 switch (event) {
999 case SND_SOC_DAPM_POST_PMU:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001000 hp_amp_power_on(component);
1001 snd_soc_component_update_bits(component, RT5640_PWR_ANLG1,
John Lin9b850ca2015-08-11 14:27:25 +08001002 RT5640_PWR_LM, RT5640_PWR_LM);
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001003 snd_soc_component_update_bits(component, RT5640_OUTPUT,
John Lin9b850ca2015-08-11 14:27:25 +08001004 RT5640_L_MUTE | RT5640_R_MUTE, 0);
1005 break;
1006
1007 case SND_SOC_DAPM_PRE_PMD:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001008 snd_soc_component_update_bits(component, RT5640_OUTPUT,
John Lin9b850ca2015-08-11 14:27:25 +08001009 RT5640_L_MUTE | RT5640_R_MUTE,
1010 RT5640_L_MUTE | RT5640_R_MUTE);
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001011 snd_soc_component_update_bits(component, RT5640_PWR_ANLG1,
John Lin9b850ca2015-08-11 14:27:25 +08001012 RT5640_PWR_LM, 0);
1013 break;
1014
1015 default:
1016 return 0;
1017 }
1018
1019 return 0;
1020}
1021
Bard Liao246693b2013-08-23 10:29:26 +08001022static int rt5640_hp_power_event(struct snd_soc_dapm_widget *w,
1023 struct snd_kcontrol *kcontrol, int event)
1024{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001025 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
Bard Liao246693b2013-08-23 10:29:26 +08001026
1027 switch (event) {
1028 case SND_SOC_DAPM_POST_PMU:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001029 hp_amp_power_on(component);
Bard Liao246693b2013-08-23 10:29:26 +08001030 break;
1031 default:
1032 return 0;
1033 }
1034
1035 return 0;
1036}
1037
1038static int rt5640_hp_post_event(struct snd_soc_dapm_widget *w,
1039 struct snd_kcontrol *kcontrol, int event)
1040{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001041 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1042 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Bard Liao246693b2013-08-23 10:29:26 +08001043
1044 switch (event) {
1045 case SND_SOC_DAPM_POST_PMU:
1046 if (!rt5640->hp_mute)
Nicholas Mc Guire4a312c92017-01-12 13:09:41 +01001047 msleep(80);
Bard Liao246693b2013-08-23 10:29:26 +08001048
1049 break;
1050
1051 default:
1052 return 0;
1053 }
1054
1055 return 0;
1056}
1057
Bard Liao997b0522013-06-11 13:10:16 +08001058static const struct snd_soc_dapm_widget rt5640_dapm_widgets[] = {
Jack Yubee3e022016-01-04 17:20:26 -06001059 /* ASRC */
1060 SND_SOC_DAPM_SUPPLY_S("Stereo Filter ASRC", 1, RT5640_ASRC_1,
1061 15, 0, NULL, 0),
1062 SND_SOC_DAPM_SUPPLY_S("I2S2 Filter ASRC", 1, RT5640_ASRC_1,
1063 12, 0, NULL, 0),
1064 SND_SOC_DAPM_SUPPLY_S("I2S2 ASRC", 1, RT5640_ASRC_1,
1065 11, 0, NULL, 0),
1066 SND_SOC_DAPM_SUPPLY_S("DMIC1 ASRC", 1, RT5640_ASRC_1,
1067 9, 0, NULL, 0),
1068 SND_SOC_DAPM_SUPPLY_S("DMIC2 ASRC", 1, RT5640_ASRC_1,
1069 8, 0, NULL, 0),
1070
1071
Bard Liao997b0522013-06-11 13:10:16 +08001072 /* Input Side */
1073 /* micbias */
1074 SND_SOC_DAPM_SUPPLY("LDO2", RT5640_PWR_ANLG1,
1075 RT5640_PWR_LDO2_BIT, 0, NULL, 0),
1076 SND_SOC_DAPM_SUPPLY("MICBIAS1", RT5640_PWR_ANLG2,
Stephen Warren9be94ae2013-06-12 15:34:23 -06001077 RT5640_PWR_MB1_BIT, 0, NULL, 0),
Bard Liao997b0522013-06-11 13:10:16 +08001078 /* Input Lines */
1079 SND_SOC_DAPM_INPUT("DMIC1"),
1080 SND_SOC_DAPM_INPUT("DMIC2"),
1081 SND_SOC_DAPM_INPUT("IN1P"),
1082 SND_SOC_DAPM_INPUT("IN1N"),
1083 SND_SOC_DAPM_INPUT("IN2P"),
1084 SND_SOC_DAPM_INPUT("IN2N"),
Oder Chiou16566e42015-10-21 09:46:05 +08001085 SND_SOC_DAPM_INPUT("IN3P"),
1086 SND_SOC_DAPM_INPUT("IN3N"),
Bard Liao997b0522013-06-11 13:10:16 +08001087 SND_SOC_DAPM_PGA("DMIC L1", SND_SOC_NOPM, 0, 0, NULL, 0),
1088 SND_SOC_DAPM_PGA("DMIC R1", SND_SOC_NOPM, 0, 0, NULL, 0),
1089 SND_SOC_DAPM_PGA("DMIC L2", SND_SOC_NOPM, 0, 0, NULL, 0),
1090 SND_SOC_DAPM_PGA("DMIC R2", SND_SOC_NOPM, 0, 0, NULL, 0),
1091
1092 SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM, 0, 0,
1093 set_dmic_clk, SND_SOC_DAPM_PRE_PMU),
Oder Chiou71d97a792014-03-28 10:46:18 +08001094 SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5640_DMIC, RT5640_DMIC_1_EN_SFT, 0,
1095 NULL, 0),
1096 SND_SOC_DAPM_SUPPLY("DMIC2 Power", RT5640_DMIC, RT5640_DMIC_2_EN_SFT, 0,
1097 NULL, 0),
Bard Liao997b0522013-06-11 13:10:16 +08001098 /* Boost */
1099 SND_SOC_DAPM_PGA("BST1", RT5640_PWR_ANLG2,
1100 RT5640_PWR_BST1_BIT, 0, NULL, 0),
1101 SND_SOC_DAPM_PGA("BST2", RT5640_PWR_ANLG2,
1102 RT5640_PWR_BST4_BIT, 0, NULL, 0),
Oder Chiou16566e42015-10-21 09:46:05 +08001103 SND_SOC_DAPM_PGA("BST3", RT5640_PWR_ANLG2,
1104 RT5640_PWR_BST2_BIT, 0, NULL, 0),
Bard Liao997b0522013-06-11 13:10:16 +08001105 /* Input Volume */
1106 SND_SOC_DAPM_PGA("INL VOL", RT5640_PWR_VOL,
1107 RT5640_PWR_IN_L_BIT, 0, NULL, 0),
1108 SND_SOC_DAPM_PGA("INR VOL", RT5640_PWR_VOL,
1109 RT5640_PWR_IN_R_BIT, 0, NULL, 0),
Bard Liao997b0522013-06-11 13:10:16 +08001110 /* REC Mixer */
1111 SND_SOC_DAPM_MIXER("RECMIXL", RT5640_PWR_MIXER, RT5640_PWR_RM_L_BIT, 0,
1112 rt5640_rec_l_mix, ARRAY_SIZE(rt5640_rec_l_mix)),
1113 SND_SOC_DAPM_MIXER("RECMIXR", RT5640_PWR_MIXER, RT5640_PWR_RM_R_BIT, 0,
1114 rt5640_rec_r_mix, ARRAY_SIZE(rt5640_rec_r_mix)),
1115 /* ADCs */
1116 SND_SOC_DAPM_ADC("ADC L", NULL, RT5640_PWR_DIG1,
1117 RT5640_PWR_ADC_L_BIT, 0),
1118 SND_SOC_DAPM_ADC("ADC R", NULL, RT5640_PWR_DIG1,
1119 RT5640_PWR_ADC_R_BIT, 0),
1120 /* ADC Mux */
1121 SND_SOC_DAPM_MUX("Stereo ADC L2 Mux", SND_SOC_NOPM, 0, 0,
1122 &rt5640_sto_adc_2_mux),
1123 SND_SOC_DAPM_MUX("Stereo ADC R2 Mux", SND_SOC_NOPM, 0, 0,
1124 &rt5640_sto_adc_2_mux),
1125 SND_SOC_DAPM_MUX("Stereo ADC L1 Mux", SND_SOC_NOPM, 0, 0,
1126 &rt5640_sto_adc_1_mux),
1127 SND_SOC_DAPM_MUX("Stereo ADC R1 Mux", SND_SOC_NOPM, 0, 0,
1128 &rt5640_sto_adc_1_mux),
1129 SND_SOC_DAPM_MUX("Mono ADC L2 Mux", SND_SOC_NOPM, 0, 0,
1130 &rt5640_mono_adc_l2_mux),
1131 SND_SOC_DAPM_MUX("Mono ADC L1 Mux", SND_SOC_NOPM, 0, 0,
1132 &rt5640_mono_adc_l1_mux),
1133 SND_SOC_DAPM_MUX("Mono ADC R1 Mux", SND_SOC_NOPM, 0, 0,
1134 &rt5640_mono_adc_r1_mux),
1135 SND_SOC_DAPM_MUX("Mono ADC R2 Mux", SND_SOC_NOPM, 0, 0,
1136 &rt5640_mono_adc_r2_mux),
1137 /* ADC Mixer */
1138 SND_SOC_DAPM_SUPPLY("Stereo Filter", RT5640_PWR_DIG2,
1139 RT5640_PWR_ADC_SF_BIT, 0, NULL, 0),
1140 SND_SOC_DAPM_MIXER("Stereo ADC MIXL", SND_SOC_NOPM, 0, 0,
1141 rt5640_sto_adc_l_mix, ARRAY_SIZE(rt5640_sto_adc_l_mix)),
1142 SND_SOC_DAPM_MIXER("Stereo ADC MIXR", SND_SOC_NOPM, 0, 0,
1143 rt5640_sto_adc_r_mix, ARRAY_SIZE(rt5640_sto_adc_r_mix)),
1144 SND_SOC_DAPM_SUPPLY("Mono Left Filter", RT5640_PWR_DIG2,
1145 RT5640_PWR_ADC_MF_L_BIT, 0, NULL, 0),
1146 SND_SOC_DAPM_MIXER("Mono ADC MIXL", SND_SOC_NOPM, 0, 0,
1147 rt5640_mono_adc_l_mix, ARRAY_SIZE(rt5640_mono_adc_l_mix)),
1148 SND_SOC_DAPM_SUPPLY("Mono Right Filter", RT5640_PWR_DIG2,
1149 RT5640_PWR_ADC_MF_R_BIT, 0, NULL, 0),
1150 SND_SOC_DAPM_MIXER("Mono ADC MIXR", SND_SOC_NOPM, 0, 0,
1151 rt5640_mono_adc_r_mix, ARRAY_SIZE(rt5640_mono_adc_r_mix)),
1152
1153 /* Digital Interface */
1154 SND_SOC_DAPM_SUPPLY("I2S1", RT5640_PWR_DIG1,
1155 RT5640_PWR_I2S1_BIT, 0, NULL, 0),
1156 SND_SOC_DAPM_PGA("IF1 DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
1157 SND_SOC_DAPM_PGA("IF1 DAC L", SND_SOC_NOPM, 0, 0, NULL, 0),
1158 SND_SOC_DAPM_PGA("IF1 DAC R", SND_SOC_NOPM, 0, 0, NULL, 0),
1159 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM, 0, 0, NULL, 0),
1160 SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM, 0, 0, NULL, 0),
1161 SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM, 0, 0, NULL, 0),
1162 SND_SOC_DAPM_SUPPLY("I2S2", RT5640_PWR_DIG1,
1163 RT5640_PWR_I2S2_BIT, 0, NULL, 0),
1164 SND_SOC_DAPM_PGA("IF2 DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
1165 SND_SOC_DAPM_PGA("IF2 DAC L", SND_SOC_NOPM, 0, 0, NULL, 0),
1166 SND_SOC_DAPM_PGA("IF2 DAC R", SND_SOC_NOPM, 0, 0, NULL, 0),
1167 SND_SOC_DAPM_PGA("IF2 ADC", SND_SOC_NOPM, 0, 0, NULL, 0),
1168 SND_SOC_DAPM_PGA("IF2 ADC L", SND_SOC_NOPM, 0, 0, NULL, 0),
1169 SND_SOC_DAPM_PGA("IF2 ADC R", SND_SOC_NOPM, 0, 0, NULL, 0),
1170 /* Digital Interface Select */
1171 SND_SOC_DAPM_MUX("DAI1 RX Mux", SND_SOC_NOPM, 0, 0, &rt5640_dai_mux),
1172 SND_SOC_DAPM_MUX("DAI1 TX Mux", SND_SOC_NOPM, 0, 0, &rt5640_dai_mux),
1173 SND_SOC_DAPM_MUX("DAI1 IF1 Mux", SND_SOC_NOPM, 0, 0, &rt5640_dai_mux),
1174 SND_SOC_DAPM_MUX("DAI1 IF2 Mux", SND_SOC_NOPM, 0, 0, &rt5640_dai_mux),
1175 SND_SOC_DAPM_MUX("SDI1 TX Mux", SND_SOC_NOPM, 0, 0, &rt5640_sdi_mux),
1176 SND_SOC_DAPM_MUX("DAI2 RX Mux", SND_SOC_NOPM, 0, 0, &rt5640_dai_mux),
1177 SND_SOC_DAPM_MUX("DAI2 TX Mux", SND_SOC_NOPM, 0, 0, &rt5640_dai_mux),
1178 SND_SOC_DAPM_MUX("DAI2 IF1 Mux", SND_SOC_NOPM, 0, 0, &rt5640_dai_mux),
1179 SND_SOC_DAPM_MUX("DAI2 IF2 Mux", SND_SOC_NOPM, 0, 0, &rt5640_dai_mux),
1180 SND_SOC_DAPM_MUX("SDI2 TX Mux", SND_SOC_NOPM, 0, 0, &rt5640_sdi_mux),
1181 /* Audio Interface */
1182 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
1183 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
1184 SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
1185 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
Oder Chiou022d21f2014-04-08 19:40:00 +08001186
Bard Liao997b0522013-06-11 13:10:16 +08001187 /* Output Side */
1188 /* DAC mixer before sound effect */
1189 SND_SOC_DAPM_MIXER("DAC MIXL", SND_SOC_NOPM, 0, 0,
1190 rt5640_dac_l_mix, ARRAY_SIZE(rt5640_dac_l_mix)),
1191 SND_SOC_DAPM_MIXER("DAC MIXR", SND_SOC_NOPM, 0, 0,
1192 rt5640_dac_r_mix, ARRAY_SIZE(rt5640_dac_r_mix)),
Oder Chiou022d21f2014-04-08 19:40:00 +08001193
Bard Liao997b0522013-06-11 13:10:16 +08001194 /* DAC Mixer */
Bard Liao997b0522013-06-11 13:10:16 +08001195 SND_SOC_DAPM_MIXER("Mono DAC MIXL", SND_SOC_NOPM, 0, 0,
1196 rt5640_mono_dac_l_mix, ARRAY_SIZE(rt5640_mono_dac_l_mix)),
1197 SND_SOC_DAPM_MIXER("Mono DAC MIXR", SND_SOC_NOPM, 0, 0,
1198 rt5640_mono_dac_r_mix, ARRAY_SIZE(rt5640_mono_dac_r_mix)),
1199 SND_SOC_DAPM_MIXER("DIG MIXL", SND_SOC_NOPM, 0, 0,
1200 rt5640_dig_l_mix, ARRAY_SIZE(rt5640_dig_l_mix)),
1201 SND_SOC_DAPM_MIXER("DIG MIXR", SND_SOC_NOPM, 0, 0,
1202 rt5640_dig_r_mix, ARRAY_SIZE(rt5640_dig_r_mix)),
1203 /* DACs */
Bard Liao57586fb2016-03-07 15:09:38 +08001204 SND_SOC_DAPM_DAC("DAC L1", NULL, SND_SOC_NOPM,
1205 0, 0),
1206 SND_SOC_DAPM_DAC("DAC R1", NULL, SND_SOC_NOPM,
1207 0, 0),
1208 SND_SOC_DAPM_SUPPLY("DAC L1 Power", RT5640_PWR_DIG1,
1209 RT5640_PWR_DAC_L1_BIT, 0, NULL, 0),
1210 SND_SOC_DAPM_SUPPLY("DAC R1 Power", RT5640_PWR_DIG1,
1211 RT5640_PWR_DAC_R1_BIT, 0, NULL, 0),
Bard Liao80317c22017-01-04 13:14:12 +08001212 SND_SOC_DAPM_SUPPLY("DAC L2 Power", RT5640_PWR_DIG1,
1213 RT5640_PWR_DAC_L2_BIT, 0, NULL, 0),
1214 SND_SOC_DAPM_SUPPLY("DAC R2 Power", RT5640_PWR_DIG1,
1215 RT5640_PWR_DAC_R2_BIT, 0, NULL, 0),
Bard Liao997b0522013-06-11 13:10:16 +08001216 /* SPK/OUT Mixer */
1217 SND_SOC_DAPM_MIXER("SPK MIXL", RT5640_PWR_MIXER, RT5640_PWR_SM_L_BIT,
1218 0, rt5640_spk_l_mix, ARRAY_SIZE(rt5640_spk_l_mix)),
1219 SND_SOC_DAPM_MIXER("SPK MIXR", RT5640_PWR_MIXER, RT5640_PWR_SM_R_BIT,
1220 0, rt5640_spk_r_mix, ARRAY_SIZE(rt5640_spk_r_mix)),
Bard Liao997b0522013-06-11 13:10:16 +08001221 /* Ouput Volume */
1222 SND_SOC_DAPM_PGA("SPKVOL L", RT5640_PWR_VOL,
1223 RT5640_PWR_SV_L_BIT, 0, NULL, 0),
1224 SND_SOC_DAPM_PGA("SPKVOL R", RT5640_PWR_VOL,
1225 RT5640_PWR_SV_R_BIT, 0, NULL, 0),
1226 SND_SOC_DAPM_PGA("OUTVOL L", RT5640_PWR_VOL,
1227 RT5640_PWR_OV_L_BIT, 0, NULL, 0),
1228 SND_SOC_DAPM_PGA("OUTVOL R", RT5640_PWR_VOL,
1229 RT5640_PWR_OV_R_BIT, 0, NULL, 0),
1230 SND_SOC_DAPM_PGA("HPOVOL L", RT5640_PWR_VOL,
1231 RT5640_PWR_HV_L_BIT, 0, NULL, 0),
1232 SND_SOC_DAPM_PGA("HPOVOL R", RT5640_PWR_VOL,
1233 RT5640_PWR_HV_R_BIT, 0, NULL, 0),
1234 /* SPO/HPO/LOUT/Mono Mixer */
1235 SND_SOC_DAPM_MIXER("SPOL MIX", SND_SOC_NOPM, 0,
1236 0, rt5640_spo_l_mix, ARRAY_SIZE(rt5640_spo_l_mix)),
1237 SND_SOC_DAPM_MIXER("SPOR MIX", SND_SOC_NOPM, 0,
1238 0, rt5640_spo_r_mix, ARRAY_SIZE(rt5640_spo_r_mix)),
John Lin9b850ca2015-08-11 14:27:25 +08001239 SND_SOC_DAPM_MIXER("LOUT MIX", SND_SOC_NOPM, 0, 0,
Bard Liao997b0522013-06-11 13:10:16 +08001240 rt5640_lout_mix, ARRAY_SIZE(rt5640_lout_mix)),
Bard Liao246693b2013-08-23 10:29:26 +08001241 SND_SOC_DAPM_SUPPLY_S("Improve HP Amp Drv", 1, SND_SOC_NOPM,
1242 0, 0, rt5640_hp_power_event, SND_SOC_DAPM_POST_PMU),
1243 SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM, 0, 0,
1244 rt5640_hp_event,
1245 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
John Lin9b850ca2015-08-11 14:27:25 +08001246 SND_SOC_DAPM_PGA_S("LOUT amp", 1, SND_SOC_NOPM, 0, 0,
1247 rt5640_lout_event,
1248 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
Bard Liao246693b2013-08-23 10:29:26 +08001249 SND_SOC_DAPM_SUPPLY("HP L Amp", RT5640_PWR_ANLG1,
Bard Liao997b0522013-06-11 13:10:16 +08001250 RT5640_PWR_HP_L_BIT, 0, NULL, 0),
Bard Liao246693b2013-08-23 10:29:26 +08001251 SND_SOC_DAPM_SUPPLY("HP R Amp", RT5640_PWR_ANLG1,
Bard Liao997b0522013-06-11 13:10:16 +08001252 RT5640_PWR_HP_R_BIT, 0, NULL, 0),
1253 SND_SOC_DAPM_SUPPLY("Improve SPK Amp Drv", RT5640_PWR_DIG1,
Bard Liao246693b2013-08-23 10:29:26 +08001254 RT5640_PWR_CLS_D_BIT, 0, NULL, 0),
1255
1256 /* Output Switch */
1257 SND_SOC_DAPM_SWITCH("Speaker L Playback", SND_SOC_NOPM, 0, 0,
1258 &spk_l_enable_control),
1259 SND_SOC_DAPM_SWITCH("Speaker R Playback", SND_SOC_NOPM, 0, 0,
1260 &spk_r_enable_control),
1261 SND_SOC_DAPM_SWITCH("HP L Playback", SND_SOC_NOPM, 0, 0,
1262 &hp_l_enable_control),
1263 SND_SOC_DAPM_SWITCH("HP R Playback", SND_SOC_NOPM, 0, 0,
1264 &hp_r_enable_control),
1265 SND_SOC_DAPM_POST("HP Post", rt5640_hp_post_event),
Bard Liao997b0522013-06-11 13:10:16 +08001266 /* Output Lines */
1267 SND_SOC_DAPM_OUTPUT("SPOLP"),
1268 SND_SOC_DAPM_OUTPUT("SPOLN"),
1269 SND_SOC_DAPM_OUTPUT("SPORP"),
1270 SND_SOC_DAPM_OUTPUT("SPORN"),
1271 SND_SOC_DAPM_OUTPUT("HPOL"),
1272 SND_SOC_DAPM_OUTPUT("HPOR"),
1273 SND_SOC_DAPM_OUTPUT("LOUTL"),
1274 SND_SOC_DAPM_OUTPUT("LOUTR"),
Oder Chiou022d21f2014-04-08 19:40:00 +08001275};
1276
1277static const struct snd_soc_dapm_widget rt5640_specific_dapm_widgets[] = {
1278 /* Audio DSP */
1279 SND_SOC_DAPM_PGA("Audio DSP", SND_SOC_NOPM, 0, 0, NULL, 0),
1280 /* ANC */
1281 SND_SOC_DAPM_PGA("ANC", SND_SOC_NOPM, 0, 0, NULL, 0),
1282
1283 /* DAC2 channel Mux */
1284 SND_SOC_DAPM_MUX("DAC L2 Mux", SND_SOC_NOPM, 0, 0, &rt5640_dac_l2_mux),
1285 SND_SOC_DAPM_MUX("DAC R2 Mux", SND_SOC_NOPM, 0, 0, &rt5640_dac_r2_mux),
1286
1287 SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM, 0, 0,
1288 rt5640_sto_dac_l_mix, ARRAY_SIZE(rt5640_sto_dac_l_mix)),
1289 SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM, 0, 0,
1290 rt5640_sto_dac_r_mix, ARRAY_SIZE(rt5640_sto_dac_r_mix)),
1291
Bard Liao57586fb2016-03-07 15:09:38 +08001292 SND_SOC_DAPM_DAC("DAC R2", NULL, SND_SOC_NOPM, 0,
Oder Chiou022d21f2014-04-08 19:40:00 +08001293 0),
Bard Liao57586fb2016-03-07 15:09:38 +08001294 SND_SOC_DAPM_DAC("DAC L2", NULL, SND_SOC_NOPM, 0,
Oder Chiou022d21f2014-04-08 19:40:00 +08001295 0),
1296
1297 SND_SOC_DAPM_MIXER("OUT MIXL", RT5640_PWR_MIXER, RT5640_PWR_OM_L_BIT,
1298 0, rt5640_out_l_mix, ARRAY_SIZE(rt5640_out_l_mix)),
1299 SND_SOC_DAPM_MIXER("OUT MIXR", RT5640_PWR_MIXER, RT5640_PWR_OM_R_BIT,
1300 0, rt5640_out_r_mix, ARRAY_SIZE(rt5640_out_r_mix)),
1301
1302 SND_SOC_DAPM_MIXER("HPO MIX L", SND_SOC_NOPM, 0, 0,
1303 rt5640_hpo_mix, ARRAY_SIZE(rt5640_hpo_mix)),
1304 SND_SOC_DAPM_MIXER("HPO MIX R", SND_SOC_NOPM, 0, 0,
1305 rt5640_hpo_mix, ARRAY_SIZE(rt5640_hpo_mix)),
1306
1307 SND_SOC_DAPM_MIXER("Mono MIX", RT5640_PWR_ANLG1, RT5640_PWR_MM_BIT, 0,
1308 rt5640_mono_mix, ARRAY_SIZE(rt5640_mono_mix)),
1309 SND_SOC_DAPM_SUPPLY("Improve MONO Amp Drv", RT5640_PWR_ANLG1,
1310 RT5640_PWR_MA_BIT, 0, NULL, 0),
1311
Bard Liao997b0522013-06-11 13:10:16 +08001312 SND_SOC_DAPM_OUTPUT("MONOP"),
1313 SND_SOC_DAPM_OUTPUT("MONON"),
1314};
1315
Oder Chiou022d21f2014-04-08 19:40:00 +08001316static const struct snd_soc_dapm_widget rt5639_specific_dapm_widgets[] = {
1317 SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM, 0, 0,
1318 rt5639_sto_dac_l_mix, ARRAY_SIZE(rt5639_sto_dac_l_mix)),
1319 SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM, 0, 0,
1320 rt5639_sto_dac_r_mix, ARRAY_SIZE(rt5639_sto_dac_r_mix)),
1321
Oder Chiou022d21f2014-04-08 19:40:00 +08001322 SND_SOC_DAPM_MIXER("OUT MIXL", RT5640_PWR_MIXER, RT5640_PWR_OM_L_BIT,
1323 0, rt5639_out_l_mix, ARRAY_SIZE(rt5639_out_l_mix)),
1324 SND_SOC_DAPM_MIXER("OUT MIXR", RT5640_PWR_MIXER, RT5640_PWR_OM_R_BIT,
1325 0, rt5639_out_r_mix, ARRAY_SIZE(rt5639_out_r_mix)),
1326
1327 SND_SOC_DAPM_MIXER("HPO MIX L", SND_SOC_NOPM, 0, 0,
1328 rt5639_hpo_mix, ARRAY_SIZE(rt5639_hpo_mix)),
1329 SND_SOC_DAPM_MIXER("HPO MIX R", SND_SOC_NOPM, 0, 0,
1330 rt5639_hpo_mix, ARRAY_SIZE(rt5639_hpo_mix)),
1331};
1332
Bard Liao997b0522013-06-11 13:10:16 +08001333static const struct snd_soc_dapm_route rt5640_dapm_routes[] = {
Jack Yubee3e022016-01-04 17:20:26 -06001334 { "I2S1", NULL, "Stereo Filter ASRC", is_using_asrc },
1335 { "I2S2", NULL, "I2S2 ASRC", is_using_asrc },
1336 { "I2S2", NULL, "I2S2 Filter ASRC", is_using_asrc },
1337 { "DMIC1", NULL, "DMIC1 ASRC", is_using_asrc },
1338 { "DMIC2", NULL, "DMIC2 ASRC", is_using_asrc },
1339
Bard Liao997b0522013-06-11 13:10:16 +08001340 {"IN1P", NULL, "LDO2"},
1341 {"IN2P", NULL, "LDO2"},
Oder Chiou16566e42015-10-21 09:46:05 +08001342 {"IN3P", NULL, "LDO2"},
Bard Liao997b0522013-06-11 13:10:16 +08001343
1344 {"DMIC L1", NULL, "DMIC1"},
1345 {"DMIC R1", NULL, "DMIC1"},
1346 {"DMIC L2", NULL, "DMIC2"},
1347 {"DMIC R2", NULL, "DMIC2"},
1348
1349 {"BST1", NULL, "IN1P"},
1350 {"BST1", NULL, "IN1N"},
1351 {"BST2", NULL, "IN2P"},
1352 {"BST2", NULL, "IN2N"},
Oder Chiou16566e42015-10-21 09:46:05 +08001353 {"BST3", NULL, "IN3P"},
1354 {"BST3", NULL, "IN3N"},
Bard Liao997b0522013-06-11 13:10:16 +08001355
1356 {"INL VOL", NULL, "IN2P"},
1357 {"INR VOL", NULL, "IN2N"},
1358
1359 {"RECMIXL", "HPOL Switch", "HPOL"},
1360 {"RECMIXL", "INL Switch", "INL VOL"},
Oder Chiou16566e42015-10-21 09:46:05 +08001361 {"RECMIXL", "BST3 Switch", "BST3"},
Bard Liao997b0522013-06-11 13:10:16 +08001362 {"RECMIXL", "BST2 Switch", "BST2"},
1363 {"RECMIXL", "BST1 Switch", "BST1"},
1364 {"RECMIXL", "OUT MIXL Switch", "OUT MIXL"},
1365
1366 {"RECMIXR", "HPOR Switch", "HPOR"},
1367 {"RECMIXR", "INR Switch", "INR VOL"},
Oder Chiou16566e42015-10-21 09:46:05 +08001368 {"RECMIXR", "BST3 Switch", "BST3"},
Bard Liao997b0522013-06-11 13:10:16 +08001369 {"RECMIXR", "BST2 Switch", "BST2"},
1370 {"RECMIXR", "BST1 Switch", "BST1"},
1371 {"RECMIXR", "OUT MIXR Switch", "OUT MIXR"},
1372
1373 {"ADC L", NULL, "RECMIXL"},
1374 {"ADC R", NULL, "RECMIXR"},
1375
1376 {"DMIC L1", NULL, "DMIC CLK"},
1377 {"DMIC L1", NULL, "DMIC1 Power"},
1378 {"DMIC R1", NULL, "DMIC CLK"},
1379 {"DMIC R1", NULL, "DMIC1 Power"},
1380 {"DMIC L2", NULL, "DMIC CLK"},
1381 {"DMIC L2", NULL, "DMIC2 Power"},
1382 {"DMIC R2", NULL, "DMIC CLK"},
1383 {"DMIC R2", NULL, "DMIC2 Power"},
1384
1385 {"Stereo ADC L2 Mux", "DMIC1", "DMIC L1"},
1386 {"Stereo ADC L2 Mux", "DMIC2", "DMIC L2"},
1387 {"Stereo ADC L2 Mux", "DIG MIX", "DIG MIXL"},
1388 {"Stereo ADC L1 Mux", "ADC", "ADC L"},
1389 {"Stereo ADC L1 Mux", "DIG MIX", "DIG MIXL"},
1390
1391 {"Stereo ADC R1 Mux", "ADC", "ADC R"},
1392 {"Stereo ADC R1 Mux", "DIG MIX", "DIG MIXR"},
1393 {"Stereo ADC R2 Mux", "DMIC1", "DMIC R1"},
1394 {"Stereo ADC R2 Mux", "DMIC2", "DMIC R2"},
1395 {"Stereo ADC R2 Mux", "DIG MIX", "DIG MIXR"},
1396
1397 {"Mono ADC L2 Mux", "DMIC L1", "DMIC L1"},
1398 {"Mono ADC L2 Mux", "DMIC L2", "DMIC L2"},
1399 {"Mono ADC L2 Mux", "Mono DAC MIXL", "Mono DAC MIXL"},
1400 {"Mono ADC L1 Mux", "Mono DAC MIXL", "Mono DAC MIXL"},
1401 {"Mono ADC L1 Mux", "ADCL", "ADC L"},
1402
1403 {"Mono ADC R1 Mux", "Mono DAC MIXR", "Mono DAC MIXR"},
1404 {"Mono ADC R1 Mux", "ADCR", "ADC R"},
1405 {"Mono ADC R2 Mux", "DMIC R1", "DMIC R1"},
1406 {"Mono ADC R2 Mux", "DMIC R2", "DMIC R2"},
1407 {"Mono ADC R2 Mux", "Mono DAC MIXR", "Mono DAC MIXR"},
1408
1409 {"Stereo ADC MIXL", "ADC1 Switch", "Stereo ADC L1 Mux"},
1410 {"Stereo ADC MIXL", "ADC2 Switch", "Stereo ADC L2 Mux"},
1411 {"Stereo ADC MIXL", NULL, "Stereo Filter"},
Bard Liao997b0522013-06-11 13:10:16 +08001412
1413 {"Stereo ADC MIXR", "ADC1 Switch", "Stereo ADC R1 Mux"},
1414 {"Stereo ADC MIXR", "ADC2 Switch", "Stereo ADC R2 Mux"},
1415 {"Stereo ADC MIXR", NULL, "Stereo Filter"},
Bard Liao997b0522013-06-11 13:10:16 +08001416
1417 {"Mono ADC MIXL", "ADC1 Switch", "Mono ADC L1 Mux"},
1418 {"Mono ADC MIXL", "ADC2 Switch", "Mono ADC L2 Mux"},
1419 {"Mono ADC MIXL", NULL, "Mono Left Filter"},
Bard Liao997b0522013-06-11 13:10:16 +08001420
1421 {"Mono ADC MIXR", "ADC1 Switch", "Mono ADC R1 Mux"},
1422 {"Mono ADC MIXR", "ADC2 Switch", "Mono ADC R2 Mux"},
1423 {"Mono ADC MIXR", NULL, "Mono Right Filter"},
Bard Liao997b0522013-06-11 13:10:16 +08001424
1425 {"IF2 ADC L", NULL, "Mono ADC MIXL"},
1426 {"IF2 ADC R", NULL, "Mono ADC MIXR"},
1427 {"IF1 ADC L", NULL, "Stereo ADC MIXL"},
1428 {"IF1 ADC R", NULL, "Stereo ADC MIXR"},
1429
1430 {"IF1 ADC", NULL, "I2S1"},
1431 {"IF1 ADC", NULL, "IF1 ADC L"},
1432 {"IF1 ADC", NULL, "IF1 ADC R"},
1433 {"IF2 ADC", NULL, "I2S2"},
1434 {"IF2 ADC", NULL, "IF2 ADC L"},
1435 {"IF2 ADC", NULL, "IF2 ADC R"},
1436
1437 {"DAI1 TX Mux", "1:1|2:2", "IF1 ADC"},
1438 {"DAI1 TX Mux", "1:2|2:1", "IF2 ADC"},
1439 {"DAI1 IF1 Mux", "1:1|2:1", "IF1 ADC"},
1440 {"DAI1 IF2 Mux", "1:1|2:1", "IF2 ADC"},
1441 {"SDI1 TX Mux", "IF1", "DAI1 IF1 Mux"},
1442 {"SDI1 TX Mux", "IF2", "DAI1 IF2 Mux"},
1443
1444 {"DAI2 TX Mux", "1:2|2:1", "IF1 ADC"},
1445 {"DAI2 TX Mux", "1:1|2:2", "IF2 ADC"},
1446 {"DAI2 IF1 Mux", "1:2|2:2", "IF1 ADC"},
1447 {"DAI2 IF2 Mux", "1:2|2:2", "IF2 ADC"},
1448 {"SDI2 TX Mux", "IF1", "DAI2 IF1 Mux"},
1449 {"SDI2 TX Mux", "IF2", "DAI2 IF2 Mux"},
1450
1451 {"AIF1TX", NULL, "DAI1 TX Mux"},
1452 {"AIF1TX", NULL, "SDI1 TX Mux"},
1453 {"AIF2TX", NULL, "DAI2 TX Mux"},
1454 {"AIF2TX", NULL, "SDI2 TX Mux"},
1455
1456 {"DAI1 RX Mux", "1:1|2:2", "AIF1RX"},
1457 {"DAI1 RX Mux", "1:1|2:1", "AIF1RX"},
1458 {"DAI1 RX Mux", "1:2|2:1", "AIF2RX"},
1459 {"DAI1 RX Mux", "1:2|2:2", "AIF2RX"},
1460
1461 {"DAI2 RX Mux", "1:2|2:1", "AIF1RX"},
1462 {"DAI2 RX Mux", "1:1|2:1", "AIF1RX"},
1463 {"DAI2 RX Mux", "1:1|2:2", "AIF2RX"},
1464 {"DAI2 RX Mux", "1:2|2:2", "AIF2RX"},
1465
1466 {"IF1 DAC", NULL, "I2S1"},
1467 {"IF1 DAC", NULL, "DAI1 RX Mux"},
1468 {"IF2 DAC", NULL, "I2S2"},
1469 {"IF2 DAC", NULL, "DAI2 RX Mux"},
1470
1471 {"IF1 DAC L", NULL, "IF1 DAC"},
1472 {"IF1 DAC R", NULL, "IF1 DAC"},
1473 {"IF2 DAC L", NULL, "IF2 DAC"},
1474 {"IF2 DAC R", NULL, "IF2 DAC"},
1475
1476 {"DAC MIXL", "Stereo ADC Switch", "Stereo ADC MIXL"},
1477 {"DAC MIXL", "INF1 Switch", "IF1 DAC L"},
Bard Liao57586fb2016-03-07 15:09:38 +08001478 {"DAC MIXL", NULL, "DAC L1 Power"},
Bard Liao997b0522013-06-11 13:10:16 +08001479 {"DAC MIXR", "Stereo ADC Switch", "Stereo ADC MIXR"},
1480 {"DAC MIXR", "INF1 Switch", "IF1 DAC R"},
Bard Liao57586fb2016-03-07 15:09:38 +08001481 {"DAC MIXR", NULL, "DAC R1 Power"},
Bard Liao997b0522013-06-11 13:10:16 +08001482
Bard Liao997b0522013-06-11 13:10:16 +08001483 {"Stereo DAC MIXL", "DAC L1 Switch", "DAC MIXL"},
Bard Liao997b0522013-06-11 13:10:16 +08001484 {"Stereo DAC MIXR", "DAC R1 Switch", "DAC MIXR"},
Bard Liao997b0522013-06-11 13:10:16 +08001485
1486 {"Mono DAC MIXL", "DAC L1 Switch", "DAC MIXL"},
Bard Liao997b0522013-06-11 13:10:16 +08001487 {"Mono DAC MIXR", "DAC R1 Switch", "DAC MIXR"},
Bard Liao997b0522013-06-11 13:10:16 +08001488
1489 {"DIG MIXL", "DAC L1 Switch", "DAC MIXL"},
Bard Liao997b0522013-06-11 13:10:16 +08001490 {"DIG MIXR", "DAC R1 Switch", "DAC MIXR"},
Bard Liao997b0522013-06-11 13:10:16 +08001491
1492 {"DAC L1", NULL, "Stereo DAC MIXL"},
Bard Liao57586fb2016-03-07 15:09:38 +08001493 {"DAC L1", NULL, "DAC L1 Power"},
Bard Liao997b0522013-06-11 13:10:16 +08001494 {"DAC R1", NULL, "Stereo DAC MIXR"},
Bard Liao57586fb2016-03-07 15:09:38 +08001495 {"DAC R1", NULL, "DAC R1 Power"},
Bard Liao997b0522013-06-11 13:10:16 +08001496
1497 {"SPK MIXL", "REC MIXL Switch", "RECMIXL"},
1498 {"SPK MIXL", "INL Switch", "INL VOL"},
1499 {"SPK MIXL", "DAC L1 Switch", "DAC L1"},
Bard Liao997b0522013-06-11 13:10:16 +08001500 {"SPK MIXL", "OUT MIXL Switch", "OUT MIXL"},
1501 {"SPK MIXR", "REC MIXR Switch", "RECMIXR"},
1502 {"SPK MIXR", "INR Switch", "INR VOL"},
1503 {"SPK MIXR", "DAC R1 Switch", "DAC R1"},
Bard Liao997b0522013-06-11 13:10:16 +08001504 {"SPK MIXR", "OUT MIXR Switch", "OUT MIXR"},
1505
Bard Liao997b0522013-06-11 13:10:16 +08001506 {"OUT MIXL", "BST1 Switch", "BST1"},
1507 {"OUT MIXL", "INL Switch", "INL VOL"},
1508 {"OUT MIXL", "REC MIXL Switch", "RECMIXL"},
Bard Liao997b0522013-06-11 13:10:16 +08001509 {"OUT MIXL", "DAC L1 Switch", "DAC L1"},
1510
Bard Liao997b0522013-06-11 13:10:16 +08001511 {"OUT MIXR", "BST2 Switch", "BST2"},
1512 {"OUT MIXR", "BST1 Switch", "BST1"},
1513 {"OUT MIXR", "INR Switch", "INR VOL"},
1514 {"OUT MIXR", "REC MIXR Switch", "RECMIXR"},
Bard Liao997b0522013-06-11 13:10:16 +08001515 {"OUT MIXR", "DAC R1 Switch", "DAC R1"},
1516
1517 {"SPKVOL L", NULL, "SPK MIXL"},
1518 {"SPKVOL R", NULL, "SPK MIXR"},
1519 {"HPOVOL L", NULL, "OUT MIXL"},
1520 {"HPOVOL R", NULL, "OUT MIXR"},
1521 {"OUTVOL L", NULL, "OUT MIXL"},
1522 {"OUTVOL R", NULL, "OUT MIXR"},
1523
1524 {"SPOL MIX", "DAC R1 Switch", "DAC R1"},
1525 {"SPOL MIX", "DAC L1 Switch", "DAC L1"},
1526 {"SPOL MIX", "SPKVOL R Switch", "SPKVOL R"},
1527 {"SPOL MIX", "SPKVOL L Switch", "SPKVOL L"},
1528 {"SPOL MIX", "BST1 Switch", "BST1"},
1529 {"SPOR MIX", "DAC R1 Switch", "DAC R1"},
1530 {"SPOR MIX", "SPKVOL R Switch", "SPKVOL R"},
1531 {"SPOR MIX", "BST1 Switch", "BST1"},
1532
Bard Liao997b0522013-06-11 13:10:16 +08001533 {"HPO MIX L", "HPO MIX DAC1 Switch", "DAC L1"},
1534 {"HPO MIX L", "HPO MIX HPVOL Switch", "HPOVOL L"},
Bard Liao246693b2013-08-23 10:29:26 +08001535 {"HPO MIX L", NULL, "HP L Amp"},
Bard Liao997b0522013-06-11 13:10:16 +08001536 {"HPO MIX R", "HPO MIX DAC1 Switch", "DAC R1"},
1537 {"HPO MIX R", "HPO MIX HPVOL Switch", "HPOVOL R"},
Bard Liao246693b2013-08-23 10:29:26 +08001538 {"HPO MIX R", NULL, "HP R Amp"},
Bard Liao997b0522013-06-11 13:10:16 +08001539
1540 {"LOUT MIX", "DAC L1 Switch", "DAC L1"},
1541 {"LOUT MIX", "DAC R1 Switch", "DAC R1"},
1542 {"LOUT MIX", "OUTVOL L Switch", "OUTVOL L"},
1543 {"LOUT MIX", "OUTVOL R Switch", "OUTVOL R"},
1544
Bard Liao246693b2013-08-23 10:29:26 +08001545 {"HP Amp", NULL, "HPO MIX L"},
1546 {"HP Amp", NULL, "HPO MIX R"},
Bard Liao997b0522013-06-11 13:10:16 +08001547
Bard Liao246693b2013-08-23 10:29:26 +08001548 {"Speaker L Playback", "Switch", "SPOL MIX"},
1549 {"Speaker R Playback", "Switch", "SPOR MIX"},
1550 {"SPOLP", NULL, "Speaker L Playback"},
1551 {"SPOLN", NULL, "Speaker L Playback"},
1552 {"SPORP", NULL, "Speaker R Playback"},
1553 {"SPORN", NULL, "Speaker R Playback"},
Bard Liao997b0522013-06-11 13:10:16 +08001554
1555 {"SPOLP", NULL, "Improve SPK Amp Drv"},
1556 {"SPOLN", NULL, "Improve SPK Amp Drv"},
1557 {"SPORP", NULL, "Improve SPK Amp Drv"},
1558 {"SPORN", NULL, "Improve SPK Amp Drv"},
1559
1560 {"HPOL", NULL, "Improve HP Amp Drv"},
1561 {"HPOR", NULL, "Improve HP Amp Drv"},
1562
Bard Liao246693b2013-08-23 10:29:26 +08001563 {"HP L Playback", "Switch", "HP Amp"},
1564 {"HP R Playback", "Switch", "HP Amp"},
1565 {"HPOL", NULL, "HP L Playback"},
1566 {"HPOR", NULL, "HP R Playback"},
John Lin9b850ca2015-08-11 14:27:25 +08001567
1568 {"LOUT amp", NULL, "LOUT MIX"},
1569 {"LOUTL", NULL, "LOUT amp"},
1570 {"LOUTR", NULL, "LOUT amp"},
Oder Chiou022d21f2014-04-08 19:40:00 +08001571};
1572
1573static const struct snd_soc_dapm_route rt5640_specific_dapm_routes[] = {
1574 {"ANC", NULL, "Stereo ADC MIXL"},
1575 {"ANC", NULL, "Stereo ADC MIXR"},
1576
1577 {"Audio DSP", NULL, "DAC MIXL"},
1578 {"Audio DSP", NULL, "DAC MIXR"},
1579
1580 {"DAC L2 Mux", "IF2", "IF2 DAC L"},
1581 {"DAC L2 Mux", "Base L/R", "Audio DSP"},
Bard Liao57586fb2016-03-07 15:09:38 +08001582 {"DAC L2 Mux", NULL, "DAC L2 Power"},
Oder Chiou022d21f2014-04-08 19:40:00 +08001583 {"DAC R2 Mux", "IF2", "IF2 DAC R"},
Bard Liao57586fb2016-03-07 15:09:38 +08001584 {"DAC R2 Mux", NULL, "DAC R2 Power"},
Oder Chiou022d21f2014-04-08 19:40:00 +08001585
1586 {"Stereo DAC MIXL", "DAC L2 Switch", "DAC L2 Mux"},
1587 {"Stereo DAC MIXL", "ANC Switch", "ANC"},
1588 {"Stereo DAC MIXR", "DAC R2 Switch", "DAC R2 Mux"},
1589 {"Stereo DAC MIXR", "ANC Switch", "ANC"},
1590
1591 {"Mono DAC MIXL", "DAC L2 Switch", "DAC L2 Mux"},
1592 {"Mono DAC MIXL", "DAC R2 Switch", "DAC R2 Mux"},
1593
1594 {"Mono DAC MIXR", "DAC R2 Switch", "DAC R2 Mux"},
1595 {"Mono DAC MIXR", "DAC L2 Switch", "DAC L2 Mux"},
1596
1597 {"DIG MIXR", "DAC R2 Switch", "DAC R2 Mux"},
1598 {"DIG MIXL", "DAC L2 Switch", "DAC L2 Mux"},
1599
1600 {"DAC L2", NULL, "Mono DAC MIXL"},
Bard Liao57586fb2016-03-07 15:09:38 +08001601 {"DAC L2", NULL, "DAC L2 Power"},
Oder Chiou022d21f2014-04-08 19:40:00 +08001602 {"DAC R2", NULL, "Mono DAC MIXR"},
Bard Liao57586fb2016-03-07 15:09:38 +08001603 {"DAC R2", NULL, "DAC R2 Power"},
Oder Chiou022d21f2014-04-08 19:40:00 +08001604
1605 {"SPK MIXL", "DAC L2 Switch", "DAC L2"},
1606 {"SPK MIXR", "DAC R2 Switch", "DAC R2"},
1607
1608 {"OUT MIXL", "SPK MIXL Switch", "SPK MIXL"},
1609 {"OUT MIXR", "SPK MIXR Switch", "SPK MIXR"},
1610
1611 {"OUT MIXL", "DAC R2 Switch", "DAC R2"},
1612 {"OUT MIXL", "DAC L2 Switch", "DAC L2"},
1613
1614 {"OUT MIXR", "DAC L2 Switch", "DAC L2"},
1615 {"OUT MIXR", "DAC R2 Switch", "DAC R2"},
1616
1617 {"HPO MIX L", "HPO MIX DAC2 Switch", "DAC L2"},
1618 {"HPO MIX R", "HPO MIX DAC2 Switch", "DAC R2"},
1619
1620 {"Mono MIX", "DAC R2 Switch", "DAC R2"},
1621 {"Mono MIX", "DAC L2 Switch", "DAC L2"},
1622 {"Mono MIX", "OUTVOL R Switch", "OUTVOL R"},
1623 {"Mono MIX", "OUTVOL L Switch", "OUTVOL L"},
1624 {"Mono MIX", "BST1 Switch", "BST1"},
1625
Bard Liao997b0522013-06-11 13:10:16 +08001626 {"MONOP", NULL, "Mono MIX"},
1627 {"MONON", NULL, "Mono MIX"},
1628 {"MONOP", NULL, "Improve MONO Amp Drv"},
1629};
1630
Oder Chiou022d21f2014-04-08 19:40:00 +08001631static const struct snd_soc_dapm_route rt5639_specific_dapm_routes[] = {
1632 {"Stereo DAC MIXL", "DAC L2 Switch", "IF2 DAC L"},
1633 {"Stereo DAC MIXR", "DAC R2 Switch", "IF2 DAC R"},
1634
1635 {"Mono DAC MIXL", "DAC L2 Switch", "IF2 DAC L"},
1636 {"Mono DAC MIXL", "DAC R2 Switch", "IF2 DAC R"},
1637
1638 {"Mono DAC MIXR", "DAC R2 Switch", "IF2 DAC R"},
1639 {"Mono DAC MIXR", "DAC L2 Switch", "IF2 DAC L"},
1640
1641 {"DIG MIXL", "DAC L2 Switch", "IF2 DAC L"},
1642 {"DIG MIXR", "DAC R2 Switch", "IF2 DAC R"},
1643
Bard Liao57586fb2016-03-07 15:09:38 +08001644 {"IF2 DAC L", NULL, "DAC L2 Power"},
1645 {"IF2 DAC R", NULL, "DAC R2 Power"},
Oder Chiou022d21f2014-04-08 19:40:00 +08001646};
1647
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001648static int get_sdp_info(struct snd_soc_component *component, int dai_id)
Bard Liao997b0522013-06-11 13:10:16 +08001649{
1650 int ret = 0, val;
1651
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001652 if (component == NULL)
Bard Liao997b0522013-06-11 13:10:16 +08001653 return -EINVAL;
1654
Kuninori Morimoto467a2552020-06-16 14:21:37 +09001655 val = snd_soc_component_read(component, RT5640_I2S1_SDP);
Bard Liao997b0522013-06-11 13:10:16 +08001656 val = (val & RT5640_I2S_IF_MASK) >> RT5640_I2S_IF_SFT;
1657 switch (dai_id) {
1658 case RT5640_AIF1:
1659 switch (val) {
1660 case RT5640_IF_123:
1661 case RT5640_IF_132:
1662 ret |= RT5640_U_IF1;
1663 break;
1664 case RT5640_IF_113:
1665 ret |= RT5640_U_IF1;
Gustavo A. R. Silva3e146b52020-07-08 20:03:59 -05001666 fallthrough;
Bard Liao997b0522013-06-11 13:10:16 +08001667 case RT5640_IF_312:
1668 case RT5640_IF_213:
1669 ret |= RT5640_U_IF2;
1670 break;
1671 }
1672 break;
1673
1674 case RT5640_AIF2:
1675 switch (val) {
1676 case RT5640_IF_231:
1677 case RT5640_IF_213:
1678 ret |= RT5640_U_IF1;
1679 break;
1680 case RT5640_IF_223:
1681 ret |= RT5640_U_IF1;
Gustavo A. R. Silva3e146b52020-07-08 20:03:59 -05001682 fallthrough;
Bard Liao997b0522013-06-11 13:10:16 +08001683 case RT5640_IF_123:
1684 case RT5640_IF_321:
1685 ret |= RT5640_U_IF2;
1686 break;
1687 }
1688 break;
1689
1690 default:
1691 ret = -EINVAL;
1692 break;
1693 }
1694
1695 return ret;
1696}
1697
Bard Liao997b0522013-06-11 13:10:16 +08001698static int rt5640_hw_params(struct snd_pcm_substream *substream,
1699 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
1700{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001701 struct snd_soc_component *component = dai->component;
1702 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Takashi Iwai5a7615c2013-10-30 08:35:06 +01001703 unsigned int val_len = 0, val_clk, mask_clk;
1704 int dai_sel, pre_div, bclk_ms, frame_size;
Bard Liao997b0522013-06-11 13:10:16 +08001705
1706 rt5640->lrck[dai->id] = params_rate(params);
Oder Chioud92950e2014-05-20 15:01:55 +08001707 pre_div = rl6231_get_clk_info(rt5640->sysclk, rt5640->lrck[dai->id]);
Bard Liao997b0522013-06-11 13:10:16 +08001708 if (pre_div < 0) {
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001709 dev_err(component->dev, "Unsupported clock setting %d for DAI %d\n",
Liam Girdwood9e9cb9b2013-09-13 17:57:35 +01001710 rt5640->lrck[dai->id], dai->id);
Bard Liao997b0522013-06-11 13:10:16 +08001711 return -EINVAL;
1712 }
1713 frame_size = snd_soc_params_to_frame_size(params);
1714 if (frame_size < 0) {
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001715 dev_err(component->dev, "Unsupported frame size: %d\n", frame_size);
Bard Liao997b0522013-06-11 13:10:16 +08001716 return frame_size;
1717 }
1718 if (frame_size > 32)
1719 bclk_ms = 1;
1720 else
1721 bclk_ms = 0;
1722 rt5640->bclk[dai->id] = rt5640->lrck[dai->id] * (32 << bclk_ms);
1723
1724 dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n",
1725 rt5640->bclk[dai->id], rt5640->lrck[dai->id]);
1726 dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n",
1727 bclk_ms, pre_div, dai->id);
1728
Oder Chiou9bccae72014-03-27 19:34:51 +08001729 switch (params_width(params)) {
1730 case 16:
Bard Liao997b0522013-06-11 13:10:16 +08001731 break;
Oder Chiou9bccae72014-03-27 19:34:51 +08001732 case 20:
Bard Liao997b0522013-06-11 13:10:16 +08001733 val_len |= RT5640_I2S_DL_20;
1734 break;
Oder Chiou9bccae72014-03-27 19:34:51 +08001735 case 24:
Bard Liao997b0522013-06-11 13:10:16 +08001736 val_len |= RT5640_I2S_DL_24;
1737 break;
Oder Chiou9bccae72014-03-27 19:34:51 +08001738 case 8:
Bard Liao997b0522013-06-11 13:10:16 +08001739 val_len |= RT5640_I2S_DL_8;
1740 break;
1741 default:
1742 return -EINVAL;
1743 }
1744
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001745 dai_sel = get_sdp_info(component, dai->id);
Bard Liao997b0522013-06-11 13:10:16 +08001746 if (dai_sel < 0) {
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001747 dev_err(component->dev, "Failed to get sdp info: %d\n", dai_sel);
Bard Liao997b0522013-06-11 13:10:16 +08001748 return -EINVAL;
1749 }
1750 if (dai_sel & RT5640_U_IF1) {
1751 mask_clk = RT5640_I2S_BCLK_MS1_MASK | RT5640_I2S_PD1_MASK;
1752 val_clk = bclk_ms << RT5640_I2S_BCLK_MS1_SFT |
1753 pre_div << RT5640_I2S_PD1_SFT;
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001754 snd_soc_component_update_bits(component, RT5640_I2S1_SDP,
Bard Liao997b0522013-06-11 13:10:16 +08001755 RT5640_I2S_DL_MASK, val_len);
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001756 snd_soc_component_update_bits(component, RT5640_ADDA_CLK1, mask_clk, val_clk);
Bard Liao997b0522013-06-11 13:10:16 +08001757 }
1758 if (dai_sel & RT5640_U_IF2) {
1759 mask_clk = RT5640_I2S_BCLK_MS2_MASK | RT5640_I2S_PD2_MASK;
1760 val_clk = bclk_ms << RT5640_I2S_BCLK_MS2_SFT |
1761 pre_div << RT5640_I2S_PD2_SFT;
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001762 snd_soc_component_update_bits(component, RT5640_I2S2_SDP,
Bard Liao997b0522013-06-11 13:10:16 +08001763 RT5640_I2S_DL_MASK, val_len);
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001764 snd_soc_component_update_bits(component, RT5640_ADDA_CLK1, mask_clk, val_clk);
Bard Liao997b0522013-06-11 13:10:16 +08001765 }
1766
1767 return 0;
1768}
1769
1770static int rt5640_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1771{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001772 struct snd_soc_component *component = dai->component;
1773 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Takashi Iwai5a7615c2013-10-30 08:35:06 +01001774 unsigned int reg_val = 0;
1775 int dai_sel;
Bard Liao997b0522013-06-11 13:10:16 +08001776
1777 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1778 case SND_SOC_DAIFMT_CBM_CFM:
1779 rt5640->master[dai->id] = 1;
1780 break;
1781 case SND_SOC_DAIFMT_CBS_CFS:
1782 reg_val |= RT5640_I2S_MS_S;
1783 rt5640->master[dai->id] = 0;
1784 break;
1785 default:
1786 return -EINVAL;
1787 }
1788
1789 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1790 case SND_SOC_DAIFMT_NB_NF:
1791 break;
1792 case SND_SOC_DAIFMT_IB_NF:
1793 reg_val |= RT5640_I2S_BP_INV;
1794 break;
1795 default:
1796 return -EINVAL;
1797 }
1798
1799 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1800 case SND_SOC_DAIFMT_I2S:
1801 break;
1802 case SND_SOC_DAIFMT_LEFT_J:
1803 reg_val |= RT5640_I2S_DF_LEFT;
1804 break;
1805 case SND_SOC_DAIFMT_DSP_A:
1806 reg_val |= RT5640_I2S_DF_PCM_A;
1807 break;
1808 case SND_SOC_DAIFMT_DSP_B:
1809 reg_val |= RT5640_I2S_DF_PCM_B;
1810 break;
1811 default:
1812 return -EINVAL;
1813 }
1814
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001815 dai_sel = get_sdp_info(component, dai->id);
Bard Liao997b0522013-06-11 13:10:16 +08001816 if (dai_sel < 0) {
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001817 dev_err(component->dev, "Failed to get sdp info: %d\n", dai_sel);
Bard Liao997b0522013-06-11 13:10:16 +08001818 return -EINVAL;
1819 }
1820 if (dai_sel & RT5640_U_IF1) {
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001821 snd_soc_component_update_bits(component, RT5640_I2S1_SDP,
Bard Liao997b0522013-06-11 13:10:16 +08001822 RT5640_I2S_MS_MASK | RT5640_I2S_BP_MASK |
1823 RT5640_I2S_DF_MASK, reg_val);
1824 }
1825 if (dai_sel & RT5640_U_IF2) {
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001826 snd_soc_component_update_bits(component, RT5640_I2S2_SDP,
Bard Liao997b0522013-06-11 13:10:16 +08001827 RT5640_I2S_MS_MASK | RT5640_I2S_BP_MASK |
1828 RT5640_I2S_DF_MASK, reg_val);
1829 }
1830
1831 return 0;
1832}
1833
1834static int rt5640_set_dai_sysclk(struct snd_soc_dai *dai,
1835 int clk_id, unsigned int freq, int dir)
1836{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001837 struct snd_soc_component *component = dai->component;
1838 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Bard Liao997b0522013-06-11 13:10:16 +08001839 unsigned int reg_val = 0;
Hans de Goede8e7a1f12018-05-08 17:35:46 +02001840 unsigned int pll_bit = 0;
Bard Liao997b0522013-06-11 13:10:16 +08001841
1842 if (freq == rt5640->sysclk && clk_id == rt5640->sysclk_src)
1843 return 0;
1844
1845 switch (clk_id) {
1846 case RT5640_SCLK_S_MCLK:
1847 reg_val |= RT5640_SCLK_SRC_MCLK;
1848 break;
1849 case RT5640_SCLK_S_PLL1:
1850 reg_val |= RT5640_SCLK_SRC_PLL1;
Hans de Goede8e7a1f12018-05-08 17:35:46 +02001851 pll_bit |= RT5640_PWR_PLL;
Bard Liao997b0522013-06-11 13:10:16 +08001852 break;
Pierre-Louis Bossartc49aed72016-08-12 16:27:55 -05001853 case RT5640_SCLK_S_RCCLK:
1854 reg_val |= RT5640_SCLK_SRC_RCCLK;
1855 break;
Bard Liao997b0522013-06-11 13:10:16 +08001856 default:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001857 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id);
Bard Liao997b0522013-06-11 13:10:16 +08001858 return -EINVAL;
1859 }
Hans de Goede8e7a1f12018-05-08 17:35:46 +02001860 snd_soc_component_update_bits(component, RT5640_PWR_ANLG2,
1861 RT5640_PWR_PLL, pll_bit);
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001862 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
Bard Liao997b0522013-06-11 13:10:16 +08001863 RT5640_SCLK_SRC_MASK, reg_val);
1864 rt5640->sysclk = freq;
1865 rt5640->sysclk_src = clk_id;
1866
1867 dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id);
1868 return 0;
1869}
1870
Bard Liao997b0522013-06-11 13:10:16 +08001871static int rt5640_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source,
1872 unsigned int freq_in, unsigned int freq_out)
1873{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001874 struct snd_soc_component *component = dai->component;
1875 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Oder Chiou71c7a2d2014-05-20 15:01:54 +08001876 struct rl6231_pll_code pll_code;
Sudip Mukherjeec77dd672016-03-08 13:35:31 +05301877 int ret;
Bard Liao997b0522013-06-11 13:10:16 +08001878
1879 if (source == rt5640->pll_src && freq_in == rt5640->pll_in &&
1880 freq_out == rt5640->pll_out)
1881 return 0;
1882
1883 if (!freq_in || !freq_out) {
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001884 dev_dbg(component->dev, "PLL disabled\n");
Bard Liao997b0522013-06-11 13:10:16 +08001885
1886 rt5640->pll_in = 0;
1887 rt5640->pll_out = 0;
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001888 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
Bard Liao997b0522013-06-11 13:10:16 +08001889 RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_MCLK);
1890 return 0;
1891 }
1892
1893 switch (source) {
1894 case RT5640_PLL1_S_MCLK:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001895 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
Bard Liao997b0522013-06-11 13:10:16 +08001896 RT5640_PLL1_SRC_MASK, RT5640_PLL1_SRC_MCLK);
1897 break;
1898 case RT5640_PLL1_S_BCLK1:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001899 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
Bard Liaoc467fc02016-03-07 15:09:37 +08001900 RT5640_PLL1_SRC_MASK, RT5640_PLL1_SRC_BCLK1);
1901 break;
Bard Liao997b0522013-06-11 13:10:16 +08001902 case RT5640_PLL1_S_BCLK2:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001903 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
Bard Liaoc467fc02016-03-07 15:09:37 +08001904 RT5640_PLL1_SRC_MASK, RT5640_PLL1_SRC_BCLK2);
Bard Liao997b0522013-06-11 13:10:16 +08001905 break;
1906 default:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001907 dev_err(component->dev, "Unknown PLL source %d\n", source);
Bard Liao997b0522013-06-11 13:10:16 +08001908 return -EINVAL;
1909 }
1910
Oder Chiou71c7a2d2014-05-20 15:01:54 +08001911 ret = rl6231_pll_calc(freq_in, freq_out, &pll_code);
Bard Liao997b0522013-06-11 13:10:16 +08001912 if (ret < 0) {
Colin Ian Kinga4db95b2021-09-25 00:10:03 +01001913 dev_err(component->dev, "Unsupported input clock %d\n", freq_in);
Bard Liao997b0522013-06-11 13:10:16 +08001914 return ret;
1915 }
1916
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001917 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n",
Oder Chiou71c7a2d2014-05-20 15:01:54 +08001918 pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code),
1919 pll_code.n_code, pll_code.k_code);
Bard Liao997b0522013-06-11 13:10:16 +08001920
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001921 snd_soc_component_write(component, RT5640_PLL_CTRL1,
Pierre-Louis Bossart4fbd2972021-03-02 15:25:11 -06001922 (pll_code.n_code << RT5640_PLL_N_SFT) | pll_code.k_code);
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001923 snd_soc_component_write(component, RT5640_PLL_CTRL2,
Pierre-Louis Bossart4fbd2972021-03-02 15:25:11 -06001924 ((pll_code.m_bp ? 0 : pll_code.m_code) << RT5640_PLL_M_SFT) |
1925 (pll_code.m_bp << RT5640_PLL_M_BP_SFT));
Bard Liao997b0522013-06-11 13:10:16 +08001926
1927 rt5640->pll_in = freq_in;
1928 rt5640->pll_out = freq_out;
1929 rt5640->pll_src = source;
1930
1931 return 0;
1932}
1933
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001934static int rt5640_set_bias_level(struct snd_soc_component *component,
Bard Liao997b0522013-06-11 13:10:16 +08001935 enum snd_soc_bias_level level)
1936{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001937 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Sugar Zhang6049af02016-02-22 15:56:55 +08001938 int ret;
1939
Bard Liao997b0522013-06-11 13:10:16 +08001940 switch (level) {
Sugar Zhang6049af02016-02-22 15:56:55 +08001941 case SND_SOC_BIAS_ON:
1942 break;
1943
1944 case SND_SOC_BIAS_PREPARE:
1945 /*
1946 * SND_SOC_BIAS_PREPARE is called while preparing for a
1947 * transition to ON or away from ON. If current bias_level
1948 * is SND_SOC_BIAS_ON, then it is preparing for a transition
1949 * away from ON. Disable the clock in that case, otherwise
1950 * enable it.
1951 */
1952 if (IS_ERR(rt5640->mclk))
1953 break;
1954
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001955 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) {
Sugar Zhang6049af02016-02-22 15:56:55 +08001956 clk_disable_unprepare(rt5640->mclk);
1957 } else {
1958 ret = clk_prepare_enable(rt5640->mclk);
1959 if (ret)
1960 return ret;
1961 }
1962 break;
1963
Bard Liao997b0522013-06-11 13:10:16 +08001964 case SND_SOC_BIAS_STANDBY:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001965 if (SND_SOC_BIAS_OFF == snd_soc_component_get_bias_level(component)) {
1966 snd_soc_component_update_bits(component, RT5640_PWR_ANLG1,
Bard Liao997b0522013-06-11 13:10:16 +08001967 RT5640_PWR_VREF1 | RT5640_PWR_MB |
1968 RT5640_PWR_BG | RT5640_PWR_VREF2,
1969 RT5640_PWR_VREF1 | RT5640_PWR_MB |
1970 RT5640_PWR_BG | RT5640_PWR_VREF2);
Bard Liao246693b2013-08-23 10:29:26 +08001971 usleep_range(10000, 15000);
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001972 snd_soc_component_update_bits(component, RT5640_PWR_ANLG1,
Bard Liao997b0522013-06-11 13:10:16 +08001973 RT5640_PWR_FV1 | RT5640_PWR_FV2,
1974 RT5640_PWR_FV1 | RT5640_PWR_FV2);
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001975 snd_soc_component_update_bits(component, RT5640_DUMMY1,
Oder Chioue3dd4422021-12-01 17:56:29 +08001976 0x1, 0x1);
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001977 snd_soc_component_update_bits(component, RT5640_MICBIAS,
Bard Liao997b0522013-06-11 13:10:16 +08001978 0x0030, 0x0030);
1979 }
1980 break;
1981
1982 case SND_SOC_BIAS_OFF:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00001983 snd_soc_component_write(component, RT5640_DEPOP_M1, 0x0004);
1984 snd_soc_component_write(component, RT5640_DEPOP_M2, 0x1100);
1985 snd_soc_component_update_bits(component, RT5640_DUMMY1, 0x1, 0);
1986 snd_soc_component_write(component, RT5640_PWR_DIG1, 0x0000);
1987 snd_soc_component_write(component, RT5640_PWR_DIG2, 0x0000);
1988 snd_soc_component_write(component, RT5640_PWR_VOL, 0x0000);
1989 snd_soc_component_write(component, RT5640_PWR_MIXER, 0x0000);
1990 snd_soc_component_write(component, RT5640_PWR_ANLG1, 0x0000);
1991 snd_soc_component_write(component, RT5640_PWR_ANLG2, 0x0000);
Bard Liao997b0522013-06-11 13:10:16 +08001992 break;
1993
1994 default:
1995 break;
1996 }
Bard Liao997b0522013-06-11 13:10:16 +08001997
1998 return 0;
1999}
2000
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002001int rt5640_dmic_enable(struct snd_soc_component *component,
Jarkko Nikulacd69dc82014-10-01 15:08:14 +03002002 bool dmic1_data_pin, bool dmic2_data_pin)
2003{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002004 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Jarkko Nikulacd69dc82014-10-01 15:08:14 +03002005
2006 regmap_update_bits(rt5640->regmap, RT5640_GPIO_CTRL1,
2007 RT5640_GP2_PIN_MASK, RT5640_GP2_PIN_DMIC1_SCL);
2008
2009 if (dmic1_data_pin) {
2010 regmap_update_bits(rt5640->regmap, RT5640_DMIC,
2011 RT5640_DMIC_1_DP_MASK, RT5640_DMIC_1_DP_GPIO3);
2012 regmap_update_bits(rt5640->regmap, RT5640_GPIO_CTRL1,
2013 RT5640_GP3_PIN_MASK, RT5640_GP3_PIN_DMIC1_SDA);
2014 }
2015
2016 if (dmic2_data_pin) {
2017 regmap_update_bits(rt5640->regmap, RT5640_DMIC,
2018 RT5640_DMIC_2_DP_MASK, RT5640_DMIC_2_DP_GPIO4);
2019 regmap_update_bits(rt5640->regmap, RT5640_GPIO_CTRL1,
2020 RT5640_GP4_PIN_MASK, RT5640_GP4_PIN_DMIC2_SDA);
2021 }
2022
2023 return 0;
2024}
2025EXPORT_SYMBOL_GPL(rt5640_dmic_enable);
2026
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002027int rt5640_sel_asrc_clk_src(struct snd_soc_component *component,
Jack Yubee3e022016-01-04 17:20:26 -06002028 unsigned int filter_mask, unsigned int clk_src)
2029{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002030 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Jack Yubee3e022016-01-04 17:20:26 -06002031 unsigned int asrc2_mask = 0;
2032 unsigned int asrc2_value = 0;
2033
2034 switch (clk_src) {
2035 case RT5640_CLK_SEL_SYS:
2036 case RT5640_CLK_SEL_ASRC:
2037 break;
2038
2039 default:
2040 return -EINVAL;
2041 }
2042
2043 if (!filter_mask)
2044 return -EINVAL;
2045
2046 if (filter_mask & RT5640_DA_STEREO_FILTER) {
2047 asrc2_mask |= RT5640_STO_DAC_M_MASK;
2048 asrc2_value = (asrc2_value & ~RT5640_STO_DAC_M_MASK)
2049 | (clk_src << RT5640_STO_DAC_M_SFT);
2050 }
2051
2052 if (filter_mask & RT5640_DA_MONO_L_FILTER) {
2053 asrc2_mask |= RT5640_MDA_L_M_MASK;
2054 asrc2_value = (asrc2_value & ~RT5640_MDA_L_M_MASK)
2055 | (clk_src << RT5640_MDA_L_M_SFT);
2056 }
2057
2058 if (filter_mask & RT5640_DA_MONO_R_FILTER) {
2059 asrc2_mask |= RT5640_MDA_R_M_MASK;
2060 asrc2_value = (asrc2_value & ~RT5640_MDA_R_M_MASK)
2061 | (clk_src << RT5640_MDA_R_M_SFT);
2062 }
2063
2064 if (filter_mask & RT5640_AD_STEREO_FILTER) {
2065 asrc2_mask |= RT5640_ADC_M_MASK;
2066 asrc2_value = (asrc2_value & ~RT5640_ADC_M_MASK)
2067 | (clk_src << RT5640_ADC_M_SFT);
2068 }
2069
2070 if (filter_mask & RT5640_AD_MONO_L_FILTER) {
2071 asrc2_mask |= RT5640_MAD_L_M_MASK;
2072 asrc2_value = (asrc2_value & ~RT5640_MAD_L_M_MASK)
2073 | (clk_src << RT5640_MAD_L_M_SFT);
2074 }
2075
2076 if (filter_mask & RT5640_AD_MONO_R_FILTER) {
2077 asrc2_mask |= RT5640_MAD_R_M_MASK;
2078 asrc2_value = (asrc2_value & ~RT5640_MAD_R_M_MASK)
2079 | (clk_src << RT5640_MAD_R_M_SFT);
2080 }
2081
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002082 snd_soc_component_update_bits(component, RT5640_ASRC_2,
Jack Yubee3e022016-01-04 17:20:26 -06002083 asrc2_mask, asrc2_value);
2084
Kuninori Morimoto467a2552020-06-16 14:21:37 +09002085 if (snd_soc_component_read(component, RT5640_ASRC_2)) {
Jack Yubee3e022016-01-04 17:20:26 -06002086 rt5640->asrc_en = true;
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002087 snd_soc_component_update_bits(component, RT5640_JD_CTRL, 0x3, 0x3);
Jack Yubee3e022016-01-04 17:20:26 -06002088 } else {
2089 rt5640->asrc_en = false;
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002090 snd_soc_component_update_bits(component, RT5640_JD_CTRL, 0x3, 0x0);
Jack Yubee3e022016-01-04 17:20:26 -06002091 }
2092
2093 return 0;
2094}
2095EXPORT_SYMBOL_GPL(rt5640_sel_asrc_clk_src);
2096
Hans de Goedee3f2a662021-08-19 21:05:41 +02002097void rt5640_enable_micbias1_for_ovcd(struct snd_soc_component *component)
Hans de Goede82108042018-05-08 17:35:51 +02002098{
2099 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
2100
2101 snd_soc_dapm_mutex_lock(dapm);
2102 snd_soc_dapm_force_enable_pin_unlocked(dapm, "LDO2");
2103 snd_soc_dapm_force_enable_pin_unlocked(dapm, "MICBIAS1");
2104 /* OVCD is unreliable when used with RCCLK as sysclk-source */
2105 snd_soc_dapm_force_enable_pin_unlocked(dapm, "Platform Clock");
2106 snd_soc_dapm_sync_unlocked(dapm);
2107 snd_soc_dapm_mutex_unlock(dapm);
2108}
Hans de Goedee3f2a662021-08-19 21:05:41 +02002109EXPORT_SYMBOL_GPL(rt5640_enable_micbias1_for_ovcd);
Hans de Goede82108042018-05-08 17:35:51 +02002110
Hans de Goedee3f2a662021-08-19 21:05:41 +02002111void rt5640_disable_micbias1_for_ovcd(struct snd_soc_component *component)
Hans de Goede82108042018-05-08 17:35:51 +02002112{
2113 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
2114
2115 snd_soc_dapm_mutex_lock(dapm);
2116 snd_soc_dapm_disable_pin_unlocked(dapm, "Platform Clock");
2117 snd_soc_dapm_disable_pin_unlocked(dapm, "MICBIAS1");
2118 snd_soc_dapm_disable_pin_unlocked(dapm, "LDO2");
2119 snd_soc_dapm_sync_unlocked(dapm);
2120 snd_soc_dapm_mutex_unlock(dapm);
2121}
Hans de Goedee3f2a662021-08-19 21:05:41 +02002122EXPORT_SYMBOL_GPL(rt5640_disable_micbias1_for_ovcd);
Hans de Goede82108042018-05-08 17:35:51 +02002123
Hans de Goedeb16188a2018-05-08 17:35:52 +02002124static void rt5640_enable_micbias1_ovcd_irq(struct snd_soc_component *component)
2125{
2126 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
2127
2128 snd_soc_component_update_bits(component, RT5640_IRQ_CTRL2,
2129 RT5640_IRQ_MB1_OC_MASK, RT5640_IRQ_MB1_OC_NOR);
2130 rt5640->ovcd_irq_enabled = true;
2131}
2132
2133static void rt5640_disable_micbias1_ovcd_irq(struct snd_soc_component *component)
2134{
2135 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
2136
2137 snd_soc_component_update_bits(component, RT5640_IRQ_CTRL2,
2138 RT5640_IRQ_MB1_OC_MASK, RT5640_IRQ_MB1_OC_BP);
2139 rt5640->ovcd_irq_enabled = false;
2140}
2141
Hans de Goede82108042018-05-08 17:35:51 +02002142static void rt5640_clear_micbias1_ovcd(struct snd_soc_component *component)
2143{
2144 snd_soc_component_update_bits(component, RT5640_IRQ_CTRL2,
2145 RT5640_MB1_OC_STATUS, 0);
2146}
2147
2148static bool rt5640_micbias1_ovcd(struct snd_soc_component *component)
2149{
2150 int val;
2151
Kuninori Morimoto467a2552020-06-16 14:21:37 +09002152 val = snd_soc_component_read(component, RT5640_IRQ_CTRL2);
Hans de Goede82108042018-05-08 17:35:51 +02002153 dev_dbg(component->dev, "irq ctrl2 %#04x\n", val);
2154
2155 return (val & RT5640_MB1_OC_STATUS);
2156}
2157
2158static bool rt5640_jack_inserted(struct snd_soc_component *component)
2159{
2160 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
2161 int val;
2162
Hans de Goede701d6362022-01-06 12:01:26 +01002163 if (rt5640->jd_gpio)
2164 val = gpiod_get_value(rt5640->jd_gpio) ? RT5640_JD_STATUS : 0;
2165 else
2166 val = snd_soc_component_read(component, RT5640_INT_IRQ_ST);
2167
Hans de Goede82108042018-05-08 17:35:51 +02002168 dev_dbg(component->dev, "irq status %#04x\n", val);
2169
2170 if (rt5640->jd_inverted)
2171 return !(val & RT5640_JD_STATUS);
2172 else
2173 return (val & RT5640_JD_STATUS);
2174}
2175
Hans de Goedeb16188a2018-05-08 17:35:52 +02002176/* Jack detect and button-press timings */
Hans de Goede82108042018-05-08 17:35:51 +02002177#define JACK_SETTLE_TIME 100 /* milli seconds */
2178#define JACK_DETECT_COUNT 5
2179#define JACK_DETECT_MAXCOUNT 20 /* Aprox. 2 seconds worth of tries */
Hans de Goedeb16188a2018-05-08 17:35:52 +02002180#define JACK_UNPLUG_TIME 80 /* milli seconds */
2181#define BP_POLL_TIME 10 /* milli seconds */
2182#define BP_POLL_MAXCOUNT 200 /* assume something is wrong after this */
2183#define BP_THRESHOLD 3
2184
2185static void rt5640_start_button_press_work(struct snd_soc_component *component)
2186{
2187 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
2188
2189 rt5640->poll_count = 0;
2190 rt5640->press_count = 0;
2191 rt5640->release_count = 0;
2192 rt5640->pressed = false;
2193 rt5640->press_reported = false;
2194 rt5640_clear_micbias1_ovcd(component);
2195 schedule_delayed_work(&rt5640->bp_work, msecs_to_jiffies(BP_POLL_TIME));
2196}
2197
2198static void rt5640_button_press_work(struct work_struct *work)
2199{
2200 struct rt5640_priv *rt5640 =
2201 container_of(work, struct rt5640_priv, bp_work.work);
2202 struct snd_soc_component *component = rt5640->component;
2203
2204 /* Check the jack was not removed underneath us */
2205 if (!rt5640_jack_inserted(component))
2206 return;
2207
2208 if (rt5640_micbias1_ovcd(component)) {
2209 rt5640->release_count = 0;
2210 rt5640->press_count++;
2211 /* Remember till after JACK_UNPLUG_TIME wait */
2212 if (rt5640->press_count >= BP_THRESHOLD)
2213 rt5640->pressed = true;
2214 rt5640_clear_micbias1_ovcd(component);
2215 } else {
2216 rt5640->press_count = 0;
2217 rt5640->release_count++;
2218 }
2219
2220 /*
2221 * The pins get temporarily shorted on jack unplug, so we poll for
2222 * at least JACK_UNPLUG_TIME milli-seconds before reporting a press.
2223 */
2224 rt5640->poll_count++;
2225 if (rt5640->poll_count < (JACK_UNPLUG_TIME / BP_POLL_TIME)) {
2226 schedule_delayed_work(&rt5640->bp_work,
2227 msecs_to_jiffies(BP_POLL_TIME));
2228 return;
2229 }
2230
2231 if (rt5640->pressed && !rt5640->press_reported) {
2232 dev_dbg(component->dev, "headset button press\n");
2233 snd_soc_jack_report(rt5640->jack, SND_JACK_BTN_0,
2234 SND_JACK_BTN_0);
2235 rt5640->press_reported = true;
2236 }
2237
2238 if (rt5640->release_count >= BP_THRESHOLD) {
2239 if (rt5640->press_reported) {
2240 dev_dbg(component->dev, "headset button release\n");
2241 snd_soc_jack_report(rt5640->jack, 0, SND_JACK_BTN_0);
2242 }
2243 /* Re-enable OVCD IRQ to detect next press */
2244 rt5640_enable_micbias1_ovcd_irq(component);
2245 return; /* Stop polling */
2246 }
2247
2248 schedule_delayed_work(&rt5640->bp_work, msecs_to_jiffies(BP_POLL_TIME));
2249}
Hans de Goede82108042018-05-08 17:35:51 +02002250
Hans de Goeded21213b2021-08-19 21:05:40 +02002251int rt5640_detect_headset(struct snd_soc_component *component, struct gpio_desc *hp_det_gpio)
Hans de Goede82108042018-05-08 17:35:51 +02002252{
2253 int i, headset_count = 0, headphone_count = 0;
2254
2255 /*
2256 * We get the insertion event before the jack is fully inserted at which
2257 * point the second ring on a TRRS connector may short the 2nd ring and
2258 * sleeve contacts, also the overcurrent detection is not entirely
2259 * reliable. So we try several times with a wait in between until we
2260 * detect the same type JACK_DETECT_COUNT times in a row.
2261 */
2262 for (i = 0; i < JACK_DETECT_MAXCOUNT; i++) {
2263 /* Clear any previous over-current status flag */
2264 rt5640_clear_micbias1_ovcd(component);
2265
2266 msleep(JACK_SETTLE_TIME);
2267
2268 /* Check the jack is still connected before checking ovcd */
Hans de Goeded21213b2021-08-19 21:05:40 +02002269 if (hp_det_gpio) {
2270 if (gpiod_get_value_cansleep(hp_det_gpio))
2271 return 0;
2272 } else {
2273 if (!rt5640_jack_inserted(component))
2274 return 0;
2275 }
Hans de Goede82108042018-05-08 17:35:51 +02002276
2277 if (rt5640_micbias1_ovcd(component)) {
2278 /*
2279 * Over current detected, there is a short between the
2280 * 2nd ring contact and the ground, so a TRS connector
2281 * without a mic contact and thus plain headphones.
2282 */
2283 dev_dbg(component->dev, "jack mic-gnd shorted\n");
2284 headset_count = 0;
2285 headphone_count++;
2286 if (headphone_count == JACK_DETECT_COUNT)
2287 return SND_JACK_HEADPHONE;
2288 } else {
2289 dev_dbg(component->dev, "jack mic-gnd open\n");
2290 headphone_count = 0;
2291 headset_count++;
2292 if (headset_count == JACK_DETECT_COUNT)
2293 return SND_JACK_HEADSET;
2294 }
2295 }
2296
2297 dev_err(component->dev, "Error detecting headset vs headphones, bad contact?, assuming headphones\n");
2298 return SND_JACK_HEADPHONE;
2299}
Hans de Goeded21213b2021-08-19 21:05:40 +02002300EXPORT_SYMBOL_GPL(rt5640_detect_headset);
Hans de Goede82108042018-05-08 17:35:51 +02002301
2302static void rt5640_jack_work(struct work_struct *work)
2303{
2304 struct rt5640_priv *rt5640 =
Hans de Goedea3b1aaf2022-01-06 12:01:24 +01002305 container_of(work, struct rt5640_priv, jack_work.work);
Hans de Goede82108042018-05-08 17:35:51 +02002306 struct snd_soc_component *component = rt5640->component;
2307 int status;
2308
Oder Chiou2b9c8d22021-11-25 13:58:12 +08002309 if (rt5640->jd_src == RT5640_JD_SRC_HDA_HEADER) {
2310 int val, jack_type = 0, hda_mic_plugged, hda_hp_plugged;
2311
2312 /* mic jack */
2313 val = snd_soc_component_read(component, RT5640_INT_IRQ_ST);
2314 hda_mic_plugged = !(val & RT5640_JD_STATUS);
2315 dev_dbg(component->dev, "mic jack status %d\n",
2316 hda_mic_plugged);
2317
2318 snd_soc_component_update_bits(component, RT5640_IRQ_CTRL1,
2319 RT5640_JD_P_MASK, !hda_mic_plugged << RT5640_JD_P_SFT);
2320
2321 if (hda_mic_plugged)
2322 jack_type |= SND_JACK_MICROPHONE;
2323
2324 /* headphone jack */
2325 val = snd_soc_component_read(component, RT5640_DUMMY2);
2326 hda_hp_plugged = !(val & (0x1 << 11));
2327 dev_dbg(component->dev, "headphone jack status %d\n",
2328 hda_hp_plugged);
2329
2330 snd_soc_component_update_bits(component, RT5640_DUMMY2,
2331 (0x1 << 10), !hda_hp_plugged << 10);
2332
2333 if (hda_hp_plugged)
2334 jack_type |= SND_JACK_HEADPHONE;
2335
2336 snd_soc_jack_report(rt5640->jack, jack_type, SND_JACK_HEADSET);
2337
2338 return;
2339 }
2340
Hans de Goede82108042018-05-08 17:35:51 +02002341 if (!rt5640_jack_inserted(component)) {
2342 /* Jack removed, or spurious IRQ? */
2343 if (rt5640->jack->status & SND_JACK_HEADPHONE) {
Hans de Goedeb16188a2018-05-08 17:35:52 +02002344 if (rt5640->jack->status & SND_JACK_MICROPHONE) {
2345 cancel_delayed_work_sync(&rt5640->bp_work);
2346 rt5640_disable_micbias1_ovcd_irq(component);
2347 rt5640_disable_micbias1_for_ovcd(component);
2348 }
2349 snd_soc_jack_report(rt5640->jack, 0,
2350 SND_JACK_HEADSET | SND_JACK_BTN_0);
Hans de Goede82108042018-05-08 17:35:51 +02002351 dev_dbg(component->dev, "jack unplugged\n");
2352 }
2353 } else if (!(rt5640->jack->status & SND_JACK_HEADPHONE)) {
2354 /* Jack inserted */
Hans de Goedeb16188a2018-05-08 17:35:52 +02002355 WARN_ON(rt5640->ovcd_irq_enabled);
Hans de Goede82108042018-05-08 17:35:51 +02002356 rt5640_enable_micbias1_for_ovcd(component);
Hans de Goeded21213b2021-08-19 21:05:40 +02002357 status = rt5640_detect_headset(component, NULL);
Hans de Goedeb16188a2018-05-08 17:35:52 +02002358 if (status == SND_JACK_HEADSET) {
2359 /* Enable ovcd IRQ for button press detect. */
2360 rt5640_enable_micbias1_ovcd_irq(component);
2361 } else {
2362 /* No more need for overcurrent detect. */
2363 rt5640_disable_micbias1_for_ovcd(component);
2364 }
Hans de Goede82108042018-05-08 17:35:51 +02002365 dev_dbg(component->dev, "detect status %#02x\n", status);
2366 snd_soc_jack_report(rt5640->jack, status, SND_JACK_HEADSET);
Hans de Goedeb16188a2018-05-08 17:35:52 +02002367 } else if (rt5640->ovcd_irq_enabled && rt5640_micbias1_ovcd(component)) {
2368 dev_dbg(component->dev, "OVCD IRQ\n");
2369
2370 /*
2371 * The ovcd IRQ keeps firing while the button is pressed, so
2372 * we disable it and start polling the button until released.
2373 *
2374 * The disable will make the IRQ pin 0 again and since we get
2375 * IRQs on both edges (so as to detect both jack plugin and
2376 * unplug) this means we will immediately get another IRQ.
2377 * The ovcd_irq_enabled check above makes the 2ND IRQ a NOP.
2378 */
2379 rt5640_disable_micbias1_ovcd_irq(component);
2380 rt5640_start_button_press_work(component);
2381
2382 /*
2383 * If the jack-detect IRQ flag goes high (unplug) after our
2384 * above rt5640_jack_inserted() check and before we have
2385 * disabled the OVCD IRQ, the IRQ pin will stay high and as
2386 * we react to edges, we miss the unplug event -> recheck.
2387 */
Hans de Goedea3b1aaf2022-01-06 12:01:24 +01002388 queue_delayed_work(system_long_wq, &rt5640->jack_work, 0);
Hans de Goede82108042018-05-08 17:35:51 +02002389 }
2390}
2391
2392static irqreturn_t rt5640_irq(int irq, void *data)
2393{
2394 struct rt5640_priv *rt5640 = data;
2395
2396 if (rt5640->jack)
Hans de Goedea3b1aaf2022-01-06 12:01:24 +01002397 queue_delayed_work(system_long_wq, &rt5640->jack_work, 0);
Hans de Goede82108042018-05-08 17:35:51 +02002398
2399 return IRQ_HANDLED;
2400}
2401
Hans de Goede701d6362022-01-06 12:01:26 +01002402static irqreturn_t rt5640_jd_gpio_irq(int irq, void *data)
2403{
2404 struct rt5640_priv *rt5640 = data;
2405
2406 queue_delayed_work(system_long_wq, &rt5640->jack_work,
2407 msecs_to_jiffies(JACK_SETTLE_TIME));
2408
2409 return IRQ_HANDLED;
2410}
2411
Hans de Goede82108042018-05-08 17:35:51 +02002412static void rt5640_cancel_work(void *data)
2413{
2414 struct rt5640_priv *rt5640 = data;
2415
Hans de Goedea3b1aaf2022-01-06 12:01:24 +01002416 cancel_delayed_work_sync(&rt5640->jack_work);
Hans de Goedeb16188a2018-05-08 17:35:52 +02002417 cancel_delayed_work_sync(&rt5640->bp_work);
Hans de Goede82108042018-05-08 17:35:51 +02002418}
2419
Hans de Goedee3f2a662021-08-19 21:05:41 +02002420void rt5640_set_ovcd_params(struct snd_soc_component *component)
2421{
2422 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
2423
2424 snd_soc_component_write(component, RT5640_PR_BASE + RT5640_BIAS_CUR4,
2425 0xa800 | rt5640->ovcd_sf);
2426
2427 snd_soc_component_update_bits(component, RT5640_MICBIAS,
2428 RT5640_MIC1_OVTH_MASK | RT5640_MIC1_OVCD_MASK,
2429 rt5640->ovcd_th | RT5640_MIC1_OVCD_EN);
2430
2431 /*
2432 * The over-current-detect is only reliable in detecting the absence
2433 * of over-current, when the mic-contact in the jack is short-circuited,
2434 * the hardware periodically retries if it can apply the bias-current
2435 * leading to the ovcd status flip-flopping 1-0-1 with it being 0 about
2436 * 10% of the time, as we poll the ovcd status bit we might hit that
2437 * 10%, so we enable sticky mode and when checking OVCD we clear the
2438 * status, msleep() a bit and then check to get a reliable reading.
2439 */
2440 snd_soc_component_update_bits(component, RT5640_IRQ_CTRL2,
2441 RT5640_MB1_OC_STKY_MASK, RT5640_MB1_OC_STKY_EN);
2442}
2443EXPORT_SYMBOL_GPL(rt5640_set_ovcd_params);
2444
Hans de Goede5caab9f2021-08-19 21:05:38 +02002445static void rt5640_disable_jack_detect(struct snd_soc_component *component)
2446{
2447 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
2448
2449 /*
2450 * soc_remove_component() force-disables jack and thus rt5640->jack
2451 * could be NULL at the time of driver's module unloading.
2452 */
2453 if (!rt5640->jack)
2454 return;
2455
Hans de Goede701d6362022-01-06 12:01:26 +01002456 if (rt5640->jd_gpio_irq_requested)
2457 free_irq(rt5640->jd_gpio_irq, rt5640);
2458
2459 if (rt5640->irq_requested)
2460 free_irq(rt5640->irq, rt5640);
2461
Hans de Goede5caab9f2021-08-19 21:05:38 +02002462 rt5640_cancel_work(rt5640);
2463
2464 if (rt5640->jack->status & SND_JACK_MICROPHONE) {
2465 rt5640_disable_micbias1_ovcd_irq(component);
2466 rt5640_disable_micbias1_for_ovcd(component);
2467 snd_soc_jack_report(rt5640->jack, 0, SND_JACK_BTN_0);
2468 }
2469
Hans de Goede701d6362022-01-06 12:01:26 +01002470 rt5640->jd_gpio_irq_requested = false;
2471 rt5640->irq_requested = false;
2472 rt5640->jd_gpio = NULL;
Hans de Goede5caab9f2021-08-19 21:05:38 +02002473 rt5640->jack = NULL;
2474}
2475
Hans de Goede82108042018-05-08 17:35:51 +02002476static void rt5640_enable_jack_detect(struct snd_soc_component *component,
Hans de Goedeb35a9ab2022-01-06 12:01:25 +01002477 struct snd_soc_jack *jack,
2478 struct rt5640_set_jack_data *jack_data)
Hans de Goede82108042018-05-08 17:35:51 +02002479{
2480 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Hans de Goede15d54842021-08-19 21:05:39 +02002481 int ret;
Hans de Goede82108042018-05-08 17:35:51 +02002482
2483 /* Select JD-source */
2484 snd_soc_component_update_bits(component, RT5640_JD_CTRL,
2485 RT5640_JD_MASK, rt5640->jd_src);
2486
2487 /* Selecting GPIO01 as an interrupt */
2488 snd_soc_component_update_bits(component, RT5640_GPIO_CTRL1,
2489 RT5640_GP1_PIN_MASK, RT5640_GP1_PIN_IRQ);
2490
2491 /* Set GPIO1 output */
2492 snd_soc_component_update_bits(component, RT5640_GPIO_CTRL3,
2493 RT5640_GP1_PF_MASK, RT5640_GP1_PF_OUT);
2494
2495 /* Enabling jd2 in general control 1 */
2496 snd_soc_component_write(component, RT5640_DUMMY1, 0x3f41);
2497
2498 /* Enabling jd2 in general control 2 */
2499 snd_soc_component_write(component, RT5640_DUMMY2, 0x4001);
2500
Hans de Goedee3f2a662021-08-19 21:05:41 +02002501 rt5640_set_ovcd_params(component);
Hans de Goede82108042018-05-08 17:35:51 +02002502
Hans de Goedeb16188a2018-05-08 17:35:52 +02002503 /*
2504 * All IRQs get or-ed together, so we need the jack IRQ to report 0
2505 * when a jack is inserted so that the OVCD IRQ then toggles the IRQ
2506 * pin 0/1 instead of it being stuck to 1. So we invert the JD polarity
2507 * on systems where the hardware does not already do this.
2508 */
2509 if (rt5640->jd_inverted)
2510 snd_soc_component_write(component, RT5640_IRQ_CTRL1,
2511 RT5640_IRQ_JD_NOR);
2512 else
2513 snd_soc_component_write(component, RT5640_IRQ_CTRL1,
2514 RT5640_IRQ_JD_NOR | RT5640_JD_P_INV);
Hans de Goede82108042018-05-08 17:35:51 +02002515
2516 rt5640->jack = jack;
Hans de Goedeb16188a2018-05-08 17:35:52 +02002517 if (rt5640->jack->status & SND_JACK_MICROPHONE) {
2518 rt5640_enable_micbias1_for_ovcd(component);
2519 rt5640_enable_micbias1_ovcd_irq(component);
2520 }
2521
Hans de Goedeb35a9ab2022-01-06 12:01:25 +01002522 if (jack_data && jack_data->codec_irq_override)
2523 rt5640->irq = jack_data->codec_irq_override;
2524
Hans de Goede701d6362022-01-06 12:01:26 +01002525 if (jack_data && jack_data->jd_gpio) {
2526 rt5640->jd_gpio = jack_data->jd_gpio;
2527 rt5640->jd_gpio_irq = gpiod_to_irq(rt5640->jd_gpio);
2528
2529 ret = request_irq(rt5640->jd_gpio_irq, rt5640_jd_gpio_irq,
2530 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
2531 "rt5640-jd-gpio", rt5640);
2532 if (ret) {
2533 dev_warn(component->dev, "Failed to request jd GPIO IRQ %d: %d\n",
2534 rt5640->jd_gpio_irq, ret);
2535 rt5640_disable_jack_detect(component);
2536 return;
2537 }
2538 rt5640->jd_gpio_irq_requested = true;
2539 }
2540
Hans de Goede15d54842021-08-19 21:05:39 +02002541 ret = request_irq(rt5640->irq, rt5640_irq,
2542 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
2543 "rt5640", rt5640);
2544 if (ret) {
2545 dev_warn(component->dev, "Failed to reguest IRQ %d: %d\n", rt5640->irq, ret);
Hans de Goede15d54842021-08-19 21:05:39 +02002546 rt5640_disable_jack_detect(component);
2547 return;
2548 }
Hans de Goede701d6362022-01-06 12:01:26 +01002549 rt5640->irq_requested = true;
Hans de Goede15d54842021-08-19 21:05:39 +02002550
Hans de Goede82108042018-05-08 17:35:51 +02002551 /* sync initial jack state */
Hans de Goedea3b1aaf2022-01-06 12:01:24 +01002552 queue_delayed_work(system_long_wq, &rt5640->jack_work, 0);
Hans de Goede82108042018-05-08 17:35:51 +02002553}
2554
Oder Chiou2b9c8d22021-11-25 13:58:12 +08002555static void rt5640_enable_hda_jack_detect(
2556 struct snd_soc_component *component, struct snd_soc_jack *jack)
2557{
2558 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
2559 int ret;
2560
2561 /* Select JD1 for Mic */
2562 snd_soc_component_update_bits(component, RT5640_JD_CTRL,
2563 RT5640_JD_MASK, RT5640_JD_JD1_IN4P);
2564 snd_soc_component_write(component, RT5640_IRQ_CTRL1, RT5640_IRQ_JD_NOR);
2565
2566 /* Select JD2 for Headphone */
2567 snd_soc_component_update_bits(component, RT5640_DUMMY2, 0x1100, 0x1100);
2568
2569 /* Selecting GPIO01 as an interrupt */
2570 snd_soc_component_update_bits(component, RT5640_GPIO_CTRL1,
2571 RT5640_GP1_PIN_MASK, RT5640_GP1_PIN_IRQ);
2572
2573 /* Set GPIO1 output */
2574 snd_soc_component_update_bits(component, RT5640_GPIO_CTRL3,
2575 RT5640_GP1_PF_MASK, RT5640_GP1_PF_OUT);
2576
Oder Chioue3dd4422021-12-01 17:56:29 +08002577 snd_soc_component_update_bits(component, RT5640_DUMMY1, 0x400, 0x0);
Oder Chiou2b9c8d22021-11-25 13:58:12 +08002578
2579 rt5640->jack = jack;
2580
2581 ret = request_irq(rt5640->irq, rt5640_irq,
2582 IRQF_TRIGGER_RISING | IRQF_ONESHOT, "rt5640", rt5640);
2583 if (ret) {
2584 dev_warn(component->dev, "Failed to reguest IRQ %d: %d\n", rt5640->irq, ret);
2585 rt5640->irq = -ENXIO;
2586 return;
2587 }
2588
2589 /* sync initial jack state */
Hans de Goedea3b1aaf2022-01-06 12:01:24 +01002590 queue_delayed_work(system_long_wq, &rt5640->jack_work, 0);
Oder Chiou2b9c8d22021-11-25 13:58:12 +08002591}
2592
Hans de Goede82108042018-05-08 17:35:51 +02002593static int rt5640_set_jack(struct snd_soc_component *component,
2594 struct snd_soc_jack *jack, void *data)
2595{
Oder Chiou2b9c8d22021-11-25 13:58:12 +08002596 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
2597
2598 if (jack) {
2599 if (rt5640->jd_src == RT5640_JD_SRC_HDA_HEADER)
2600 rt5640_enable_hda_jack_detect(component, jack);
2601 else
Hans de Goedeb35a9ab2022-01-06 12:01:25 +01002602 rt5640_enable_jack_detect(component, jack, data);
Oder Chiou2b9c8d22021-11-25 13:58:12 +08002603 } else {
Hans de Goede82108042018-05-08 17:35:51 +02002604 rt5640_disable_jack_detect(component);
Oder Chiou2b9c8d22021-11-25 13:58:12 +08002605 }
Hans de Goede82108042018-05-08 17:35:51 +02002606
2607 return 0;
2608}
2609
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002610static int rt5640_probe(struct snd_soc_component *component)
Bard Liao997b0522013-06-11 13:10:16 +08002611{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002612 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
2613 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Hans de Goedefb509fa2018-05-08 17:35:50 +02002614 u32 dmic1_data_pin = 0;
2615 u32 dmic2_data_pin = 0;
2616 bool dmic_en = false;
2617 u32 val;
Bard Liao997b0522013-06-11 13:10:16 +08002618
Sugar Zhang6049af02016-02-22 15:56:55 +08002619 /* Check if MCLK provided */
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002620 rt5640->mclk = devm_clk_get(component->dev, "mclk");
Sugar Zhang6049af02016-02-22 15:56:55 +08002621 if (PTR_ERR(rt5640->mclk) == -EPROBE_DEFER)
2622 return -EPROBE_DEFER;
2623
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002624 rt5640->component = component;
Bard Liao997b0522013-06-11 13:10:16 +08002625
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002626 snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF);
Bard Liao997b0522013-06-11 13:10:16 +08002627
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002628 snd_soc_component_update_bits(component, RT5640_DUMMY1, 0x0301, 0x0301);
2629 snd_soc_component_update_bits(component, RT5640_MICBIAS, 0x0030, 0x0030);
2630 snd_soc_component_update_bits(component, RT5640_DSP_PATH2, 0xfc00, 0x0c00);
Bard Liao997b0522013-06-11 13:10:16 +08002631
Kuninori Morimoto467a2552020-06-16 14:21:37 +09002632 switch (snd_soc_component_read(component, RT5640_RESET) & RT5640_ID_MASK) {
Bard Liao8bfc6d22014-04-17 10:24:06 +08002633 case RT5640_ID_5640:
2634 case RT5640_ID_5642:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002635 snd_soc_add_component_controls(component,
Oder Chiou022d21f2014-04-08 19:40:00 +08002636 rt5640_specific_snd_controls,
2637 ARRAY_SIZE(rt5640_specific_snd_controls));
Lars-Peter Clausen76aad742015-05-19 21:49:08 +02002638 snd_soc_dapm_new_controls(dapm,
Oder Chiou022d21f2014-04-08 19:40:00 +08002639 rt5640_specific_dapm_widgets,
2640 ARRAY_SIZE(rt5640_specific_dapm_widgets));
Lars-Peter Clausen76aad742015-05-19 21:49:08 +02002641 snd_soc_dapm_add_routes(dapm,
Oder Chiou022d21f2014-04-08 19:40:00 +08002642 rt5640_specific_dapm_routes,
2643 ARRAY_SIZE(rt5640_specific_dapm_routes));
2644 break;
Bard Liao8bfc6d22014-04-17 10:24:06 +08002645 case RT5640_ID_5639:
Lars-Peter Clausen76aad742015-05-19 21:49:08 +02002646 snd_soc_dapm_new_controls(dapm,
Oder Chiou022d21f2014-04-08 19:40:00 +08002647 rt5639_specific_dapm_widgets,
2648 ARRAY_SIZE(rt5639_specific_dapm_widgets));
Lars-Peter Clausen76aad742015-05-19 21:49:08 +02002649 snd_soc_dapm_add_routes(dapm,
Oder Chiou022d21f2014-04-08 19:40:00 +08002650 rt5639_specific_dapm_routes,
2651 ARRAY_SIZE(rt5639_specific_dapm_routes));
2652 break;
Bard Liao57f174f2014-05-06 15:56:06 +08002653 default:
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002654 dev_err(component->dev,
Bard Liao57f174f2014-05-06 15:56:06 +08002655 "The driver is for RT5639 RT5640 or RT5642 only\n");
2656 return -ENODEV;
Oder Chiou022d21f2014-04-08 19:40:00 +08002657 }
2658
Hans de Goede988a5e02018-05-08 17:35:49 +02002659 /*
2660 * Note on some platforms the platform code may need to add device-props
2661 * rather then relying only on properties set by the firmware.
2662 * Therefor the property parsing MUST be done here, rather then from
2663 * rt5640_i2c_probe(), so that the platform-code can attach extra
2664 * properties before calling snd_soc_register_card().
2665 */
2666 if (device_property_read_bool(component->dev, "realtek,in1-differential"))
2667 snd_soc_component_update_bits(component, RT5640_IN1_IN2,
2668 RT5640_IN_DF1, RT5640_IN_DF1);
2669
2670 if (device_property_read_bool(component->dev, "realtek,in2-differential"))
2671 snd_soc_component_update_bits(component, RT5640_IN3_IN4,
2672 RT5640_IN_DF2, RT5640_IN_DF2);
2673
2674 if (device_property_read_bool(component->dev, "realtek,in3-differential"))
2675 snd_soc_component_update_bits(component, RT5640_IN1_IN2,
2676 RT5640_IN_DF2, RT5640_IN_DF2);
2677
Hans de Goedefb509fa2018-05-08 17:35:50 +02002678 if (device_property_read_u32(component->dev, "realtek,dmic1-data-pin",
2679 &val) == 0 && val) {
2680 dmic1_data_pin = val - 1;
2681 dmic_en = true;
2682 }
2683
2684 if (device_property_read_u32(component->dev, "realtek,dmic2-data-pin",
2685 &val) == 0 && val) {
2686 dmic2_data_pin = val - 1;
2687 dmic_en = true;
2688 }
2689
2690 if (dmic_en)
2691 rt5640_dmic_enable(component, dmic1_data_pin, dmic2_data_pin);
2692
Hans de Goede82108042018-05-08 17:35:51 +02002693 if (device_property_read_u32(component->dev,
2694 "realtek,jack-detect-source", &val) == 0) {
Oder Chioue3dd4422021-12-01 17:56:29 +08002695 if (val <= RT5640_JD_SRC_GPIO4) {
Hans de Goede82108042018-05-08 17:35:51 +02002696 rt5640->jd_src = val << RT5640_JD_SFT;
Oder Chioue3dd4422021-12-01 17:56:29 +08002697 } else if (val == RT5640_JD_SRC_HDA_HEADER) {
Oder Chiou2b9c8d22021-11-25 13:58:12 +08002698 rt5640->jd_src = RT5640_JD_SRC_HDA_HEADER;
Oder Chioue3dd4422021-12-01 17:56:29 +08002699 snd_soc_component_update_bits(component, RT5640_DUMMY1,
2700 0x0300, 0x0);
2701 } else {
Hans de Goede82108042018-05-08 17:35:51 +02002702 dev_warn(component->dev, "Warning: Invalid jack-detect-source value: %d, leaving jack-detect disabled\n",
2703 val);
Oder Chioue3dd4422021-12-01 17:56:29 +08002704 }
Hans de Goede82108042018-05-08 17:35:51 +02002705 }
2706
2707 if (!device_property_read_bool(component->dev, "realtek,jack-detect-not-inverted"))
2708 rt5640->jd_inverted = true;
2709
2710 /*
2711 * Testing on various boards has shown that good defaults for the OVCD
2712 * threshold and scale-factor are 2000µA and 0.75. For an effective
2713 * limit of 1500µA, this seems to be more reliable then 1500µA and 1.0.
2714 */
2715 rt5640->ovcd_th = RT5640_MIC1_OVTH_2000UA;
2716 rt5640->ovcd_sf = RT5640_MIC_OVCD_SF_0P75;
2717
2718 if (device_property_read_u32(component->dev,
2719 "realtek,over-current-threshold-microamp", &val) == 0) {
2720 switch (val) {
2721 case 600:
2722 rt5640->ovcd_th = RT5640_MIC1_OVTH_600UA;
2723 break;
2724 case 1500:
2725 rt5640->ovcd_th = RT5640_MIC1_OVTH_1500UA;
2726 break;
2727 case 2000:
2728 rt5640->ovcd_th = RT5640_MIC1_OVTH_2000UA;
2729 break;
2730 default:
2731 dev_warn(component->dev, "Warning: Invalid over-current-threshold-microamp value: %d, defaulting to 2000uA\n",
2732 val);
2733 }
2734 }
2735
2736 if (device_property_read_u32(component->dev,
2737 "realtek,over-current-scale-factor", &val) == 0) {
2738 if (val <= RT5640_OVCD_SF_1P5)
2739 rt5640->ovcd_sf = val << RT5640_MIC_OVCD_SF_SFT;
2740 else
2741 dev_warn(component->dev, "Warning: Invalid over-current-scale-factor value: %d, defaulting to 0.75\n",
2742 val);
2743 }
2744
Bard Liao997b0522013-06-11 13:10:16 +08002745 return 0;
2746}
2747
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002748static void rt5640_remove(struct snd_soc_component *component)
Bard Liao997b0522013-06-11 13:10:16 +08002749{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002750 rt5640_reset(component);
Bard Liao997b0522013-06-11 13:10:16 +08002751}
2752
2753#ifdef CONFIG_PM
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002754static int rt5640_suspend(struct snd_soc_component *component)
Bard Liao997b0522013-06-11 13:10:16 +08002755{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002756 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Bard Liao997b0522013-06-11 13:10:16 +08002757
Oder Chiou2b9c8d22021-11-25 13:58:12 +08002758 rt5640_cancel_work(rt5640);
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002759 snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF);
2760 rt5640_reset(component);
Bard Liao997b0522013-06-11 13:10:16 +08002761 regcache_cache_only(rt5640->regmap, true);
2762 regcache_mark_dirty(rt5640->regmap);
Hans de Goede8e3ebf52018-05-08 17:35:48 +02002763 if (gpio_is_valid(rt5640->ldo1_en))
2764 gpio_set_value_cansleep(rt5640->ldo1_en, 0);
Bard Liao997b0522013-06-11 13:10:16 +08002765
2766 return 0;
2767}
2768
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002769static int rt5640_resume(struct snd_soc_component *component)
Bard Liao997b0522013-06-11 13:10:16 +08002770{
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002771 struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
Mark Browne58f3012013-10-16 17:26:22 +01002772
Hans de Goede8e3ebf52018-05-08 17:35:48 +02002773 if (gpio_is_valid(rt5640->ldo1_en)) {
2774 gpio_set_value_cansleep(rt5640->ldo1_en, 1);
Mark Browne58f3012013-10-16 17:26:22 +01002775 msleep(400);
2776 }
Bard Liao997b0522013-06-11 13:10:16 +08002777
Oder Chiou4c9185b2014-03-27 15:55:47 +08002778 regcache_cache_only(rt5640->regmap, false);
2779 regcache_sync(rt5640->regmap);
2780
Hans de Goedea2d6d842022-01-06 12:01:23 +01002781 if (rt5640->jack) {
Oder Chiou2b9c8d22021-11-25 13:58:12 +08002782 if (rt5640->jd_src == RT5640_JD_SRC_HDA_HEADER)
2783 snd_soc_component_update_bits(component,
2784 RT5640_DUMMY2, 0x1100, 0x1100);
2785 else
2786 snd_soc_component_write(component, RT5640_DUMMY2,
2787 0x4001);
2788
Hans de Goedea3b1aaf2022-01-06 12:01:24 +01002789 queue_delayed_work(system_long_wq, &rt5640->jack_work, 0);
Oder Chiou2b9c8d22021-11-25 13:58:12 +08002790 }
2791
Bard Liao997b0522013-06-11 13:10:16 +08002792 return 0;
2793}
2794#else
2795#define rt5640_suspend NULL
2796#define rt5640_resume NULL
2797#endif
2798
2799#define RT5640_STEREO_RATES SNDRV_PCM_RATE_8000_96000
2800#define RT5640_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
2801 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
2802
Stephen Warren9be94ae2013-06-12 15:34:23 -06002803static const struct snd_soc_dai_ops rt5640_aif_dai_ops = {
Bard Liao997b0522013-06-11 13:10:16 +08002804 .hw_params = rt5640_hw_params,
2805 .set_fmt = rt5640_set_dai_fmt,
2806 .set_sysclk = rt5640_set_dai_sysclk,
2807 .set_pll = rt5640_set_dai_pll,
2808};
2809
Stephen Warren9be94ae2013-06-12 15:34:23 -06002810static struct snd_soc_dai_driver rt5640_dai[] = {
Bard Liao997b0522013-06-11 13:10:16 +08002811 {
2812 .name = "rt5640-aif1",
2813 .id = RT5640_AIF1,
2814 .playback = {
2815 .stream_name = "AIF1 Playback",
2816 .channels_min = 1,
2817 .channels_max = 2,
2818 .rates = RT5640_STEREO_RATES,
2819 .formats = RT5640_FORMATS,
2820 },
2821 .capture = {
2822 .stream_name = "AIF1 Capture",
2823 .channels_min = 1,
2824 .channels_max = 2,
2825 .rates = RT5640_STEREO_RATES,
2826 .formats = RT5640_FORMATS,
2827 },
2828 .ops = &rt5640_aif_dai_ops,
2829 },
2830 {
2831 .name = "rt5640-aif2",
2832 .id = RT5640_AIF2,
2833 .playback = {
2834 .stream_name = "AIF2 Playback",
2835 .channels_min = 1,
2836 .channels_max = 2,
2837 .rates = RT5640_STEREO_RATES,
2838 .formats = RT5640_FORMATS,
2839 },
2840 .capture = {
2841 .stream_name = "AIF2 Capture",
2842 .channels_min = 1,
2843 .channels_max = 2,
2844 .rates = RT5640_STEREO_RATES,
2845 .formats = RT5640_FORMATS,
2846 },
2847 .ops = &rt5640_aif_dai_ops,
2848 },
2849};
2850
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002851static const struct snd_soc_component_driver soc_component_dev_rt5640 = {
2852 .probe = rt5640_probe,
2853 .remove = rt5640_remove,
2854 .suspend = rt5640_suspend,
2855 .resume = rt5640_resume,
2856 .set_bias_level = rt5640_set_bias_level,
Hans de Goede82108042018-05-08 17:35:51 +02002857 .set_jack = rt5640_set_jack,
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00002858 .controls = rt5640_snd_controls,
2859 .num_controls = ARRAY_SIZE(rt5640_snd_controls),
2860 .dapm_widgets = rt5640_dapm_widgets,
2861 .num_dapm_widgets = ARRAY_SIZE(rt5640_dapm_widgets),
2862 .dapm_routes = rt5640_dapm_routes,
2863 .num_dapm_routes = ARRAY_SIZE(rt5640_dapm_routes),
2864 .use_pmdown_time = 1,
2865 .endianness = 1,
2866 .non_legacy_dai_naming = 1,
2867
Bard Liao997b0522013-06-11 13:10:16 +08002868};
2869
2870static const struct regmap_config rt5640_regmap = {
2871 .reg_bits = 8,
2872 .val_bits = 16,
David Frey1c96a2f2018-09-01 09:50:41 -07002873 .use_single_read = true,
2874 .use_single_write = true,
Bard Liao997b0522013-06-11 13:10:16 +08002875
2876 .max_register = RT5640_VENDOR_ID2 + 1 + (ARRAY_SIZE(rt5640_ranges) *
2877 RT5640_PR_SPACING),
2878 .volatile_reg = rt5640_volatile_register,
2879 .readable_reg = rt5640_readable_register,
2880
2881 .cache_type = REGCACHE_RBTREE,
2882 .reg_defaults = rt5640_reg,
2883 .num_reg_defaults = ARRAY_SIZE(rt5640_reg),
2884 .ranges = rt5640_ranges,
2885 .num_ranges = ARRAY_SIZE(rt5640_ranges),
2886};
2887
2888static const struct i2c_device_id rt5640_i2c_id[] = {
2889 { "rt5640", 0 },
Oder Chioub0c27842014-04-10 10:57:34 +08002890 { "rt5639", 0 },
Bard Liao8bfc6d22014-04-17 10:24:06 +08002891 { "rt5642", 0 },
Bard Liao997b0522013-06-11 13:10:16 +08002892 { }
2893};
2894MODULE_DEVICE_TABLE(i2c, rt5640_i2c_id);
2895
Stephen Warren03a620d2014-03-31 11:05:17 -06002896#if defined(CONFIG_OF)
2897static const struct of_device_id rt5640_of_match[] = {
Oder Chiou33fcec22014-04-28 16:55:21 +08002898 { .compatible = "realtek,rt5639", },
Stephen Warren03a620d2014-03-31 11:05:17 -06002899 { .compatible = "realtek,rt5640", },
2900 {},
2901};
2902MODULE_DEVICE_TABLE(of, rt5640_of_match);
2903#endif
2904
Thierry Reding32fcb972013-09-19 11:18:06 +02002905#ifdef CONFIG_ACPI
Mathias Krauseb895dc22015-06-13 14:25:14 +02002906static const struct acpi_device_id rt5640_acpi_match[] = {
Liam Girdwood02b80772013-09-13 17:57:36 +01002907 { "INT33CA", 0 },
Alexandrov Stansilav03200142017-01-26 14:09:31 -06002908 { "10EC3276", 0 },
Jarkko Nikulab31b2b62014-02-07 09:35:16 +02002909 { "10EC5640", 0 },
Jarkko Nikula34636672015-01-23 14:15:30 +02002910 { "10EC5642", 0 },
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -06002911 { "INTCCFFD", 0 },
Liam Girdwood02b80772013-09-13 17:57:36 +01002912 { },
2913};
2914MODULE_DEVICE_TABLE(acpi, rt5640_acpi_match);
Thierry Reding32fcb972013-09-19 11:18:06 +02002915#endif
Liam Girdwood02b80772013-09-13 17:57:36 +01002916
Stephen Warrendcad9f02013-06-12 11:34:30 -06002917static int rt5640_parse_dt(struct rt5640_priv *rt5640, struct device_node *np)
2918{
Hans de Goede8e3ebf52018-05-08 17:35:48 +02002919 rt5640->ldo1_en = of_get_named_gpio(np, "realtek,ldo1-en-gpios", 0);
Stephen Warrendcad9f02013-06-12 11:34:30 -06002920 /*
2921 * LDO1_EN is optional (it may be statically tied on the board).
2922 * -ENOENT means that the property doesn't exist, i.e. there is no
2923 * GPIO, so is not an error. Any other error code means the property
2924 * exists, but could not be parsed.
2925 */
Hans de Goede8e3ebf52018-05-08 17:35:48 +02002926 if (!gpio_is_valid(rt5640->ldo1_en) &&
2927 (rt5640->ldo1_en != -ENOENT))
2928 return rt5640->ldo1_en;
Stephen Warrendcad9f02013-06-12 11:34:30 -06002929
2930 return 0;
2931}
2932
Bard Liao997b0522013-06-11 13:10:16 +08002933static int rt5640_i2c_probe(struct i2c_client *i2c,
2934 const struct i2c_device_id *id)
2935{
Bard Liao997b0522013-06-11 13:10:16 +08002936 struct rt5640_priv *rt5640;
2937 int ret;
2938 unsigned int val;
2939
2940 rt5640 = devm_kzalloc(&i2c->dev,
2941 sizeof(struct rt5640_priv),
2942 GFP_KERNEL);
2943 if (NULL == rt5640)
2944 return -ENOMEM;
Stephen Warrendcad9f02013-06-12 11:34:30 -06002945 i2c_set_clientdata(i2c, rt5640);
2946
Hans de Goede8e3ebf52018-05-08 17:35:48 +02002947 if (i2c->dev.of_node) {
Stephen Warrendcad9f02013-06-12 11:34:30 -06002948 ret = rt5640_parse_dt(rt5640, i2c->dev.of_node);
2949 if (ret)
2950 return ret;
2951 } else
Hans de Goede8e3ebf52018-05-08 17:35:48 +02002952 rt5640->ldo1_en = -EINVAL;
Bard Liao997b0522013-06-11 13:10:16 +08002953
2954 rt5640->regmap = devm_regmap_init_i2c(i2c, &rt5640_regmap);
2955 if (IS_ERR(rt5640->regmap)) {
2956 ret = PTR_ERR(rt5640->regmap);
2957 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
2958 ret);
2959 return ret;
2960 }
2961
Hans de Goede8e3ebf52018-05-08 17:35:48 +02002962 if (gpio_is_valid(rt5640->ldo1_en)) {
2963 ret = devm_gpio_request_one(&i2c->dev, rt5640->ldo1_en,
Bard Liao997b0522013-06-11 13:10:16 +08002964 GPIOF_OUT_INIT_HIGH,
2965 "RT5640 LDO1_EN");
2966 if (ret < 0) {
2967 dev_err(&i2c->dev, "Failed to request LDO1_EN %d: %d\n",
Hans de Goede8e3ebf52018-05-08 17:35:48 +02002968 rt5640->ldo1_en, ret);
Bard Liao997b0522013-06-11 13:10:16 +08002969 return ret;
2970 }
2971 msleep(400);
2972 }
2973
2974 regmap_read(rt5640->regmap, RT5640_VENDOR_ID2, &val);
Oder Chiou3441e522014-03-28 20:28:29 +08002975 if (val != RT5640_DEVICE_ID) {
Bard Liao997b0522013-06-11 13:10:16 +08002976 dev_err(&i2c->dev,
Jarkko Nikula818454d2015-06-25 13:58:57 +03002977 "Device with ID register %#x is not rt5640/39\n", val);
Bard Liao997b0522013-06-11 13:10:16 +08002978 return -ENODEV;
2979 }
2980
2981 regmap_write(rt5640->regmap, RT5640_RESET, 0);
2982
2983 ret = regmap_register_patch(rt5640->regmap, init_list,
2984 ARRAY_SIZE(init_list));
2985 if (ret != 0)
2986 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret);
2987
Bard Liao25fb7062016-10-17 19:14:04 +08002988 regmap_update_bits(rt5640->regmap, RT5640_DUMMY1,
2989 RT5640_MCLK_DET, RT5640_MCLK_DET);
2990
Pierre-Louis Bossarte0a99922019-01-04 20:02:40 -06002991 rt5640->hp_mute = true;
Hans de Goede82108042018-05-08 17:35:51 +02002992 rt5640->irq = i2c->irq;
Hans de Goedeb16188a2018-05-08 17:35:52 +02002993 INIT_DELAYED_WORK(&rt5640->bp_work, rt5640_button_press_work);
Hans de Goedea3b1aaf2022-01-06 12:01:24 +01002994 INIT_DELAYED_WORK(&rt5640->jack_work, rt5640_jack_work);
Hans de Goede82108042018-05-08 17:35:51 +02002995
2996 /* Make sure work is stopped on probe-error / remove */
2997 ret = devm_add_action_or_reset(&i2c->dev, rt5640_cancel_work, rt5640);
2998 if (ret)
2999 return ret;
3000
Kuninori Morimotod5a41b52018-01-29 03:42:46 +00003001 return devm_snd_soc_register_component(&i2c->dev,
3002 &soc_component_dev_rt5640,
Axel Lin1657caf2014-06-10 11:35:56 +08003003 rt5640_dai, ARRAY_SIZE(rt5640_dai));
Bard Liao997b0522013-06-11 13:10:16 +08003004}
3005
Stephen Warren9be94ae2013-06-12 15:34:23 -06003006static struct i2c_driver rt5640_i2c_driver = {
Bard Liao997b0522013-06-11 13:10:16 +08003007 .driver = {
3008 .name = "rt5640",
Liam Girdwood02b80772013-09-13 17:57:36 +01003009 .acpi_match_table = ACPI_PTR(rt5640_acpi_match),
Stephen Warren03a620d2014-03-31 11:05:17 -06003010 .of_match_table = of_match_ptr(rt5640_of_match),
Bard Liao997b0522013-06-11 13:10:16 +08003011 },
3012 .probe = rt5640_i2c_probe,
Bard Liao997b0522013-06-11 13:10:16 +08003013 .id_table = rt5640_i2c_id,
3014};
3015module_i2c_driver(rt5640_i2c_driver);
3016
Oder Chioub0c27842014-04-10 10:57:34 +08003017MODULE_DESCRIPTION("ASoC RT5640/RT5639 driver");
Bard Liao997b0522013-06-11 13:10:16 +08003018MODULE_AUTHOR("Johnny Hsu <johnnyhsu@realtek.com>");
3019MODULE_LICENSE("GPL v2");