2 * rt5640.c -- RT5640/RT5639 ALSA SoC audio codec driver
4 * Copyright 2011 Realtek Semiconductor Corp.
5 * Author: Johnny Hsu <johnnyhsu@realtek.com>
6 * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
18 #include <linux/gpio.h>
19 #include <linux/i2c.h>
20 #include <linux/regmap.h>
22 #include <linux/of_gpio.h>
23 #include <linux/platform_device.h>
24 #include <linux/spi/spi.h>
25 #include <linux/acpi.h>
26 #include <sound/core.h>
27 #include <sound/pcm.h>
28 #include <sound/pcm_params.h>
29 #include <sound/soc.h>
30 #include <sound/soc-dapm.h>
31 #include <sound/initval.h>
32 #include <sound/tlv.h>
37 #define RT5640_DEVICE_ID 0x6231
39 #define RT5640_PR_RANGE_BASE (0xff + 1)
40 #define RT5640_PR_SPACING 0x100
42 #define RT5640_PR_BASE (RT5640_PR_RANGE_BASE + (0 * RT5640_PR_SPACING))
44 static const struct regmap_range_cfg rt5640_ranges
[] = {
45 { .name
= "PR", .range_min
= RT5640_PR_BASE
,
46 .range_max
= RT5640_PR_BASE
+ 0xb4,
47 .selector_reg
= RT5640_PRIV_INDEX
,
48 .selector_mask
= 0xff,
49 .selector_shift
= 0x0,
50 .window_start
= RT5640_PRIV_DATA
,
54 static const struct reg_default init_list
[] = {
55 {RT5640_PR_BASE
+ 0x3d, 0x3600},
56 {RT5640_PR_BASE
+ 0x12, 0x0aa8},
57 {RT5640_PR_BASE
+ 0x14, 0x0aaa},
58 {RT5640_PR_BASE
+ 0x20, 0x6110},
59 {RT5640_PR_BASE
+ 0x21, 0xe0e0},
60 {RT5640_PR_BASE
+ 0x23, 0x1804},
63 static const struct reg_default rt5640_reg
[] = {
169 static int rt5640_reset(struct snd_soc_codec
*codec
)
171 return snd_soc_write(codec
, RT5640_RESET
, 0);
174 static bool rt5640_volatile_register(struct device
*dev
, unsigned int reg
)
178 for (i
= 0; i
< ARRAY_SIZE(rt5640_ranges
); i
++)
179 if ((reg
>= rt5640_ranges
[i
].window_start
&&
180 reg
<= rt5640_ranges
[i
].window_start
+
181 rt5640_ranges
[i
].window_len
) ||
182 (reg
>= rt5640_ranges
[i
].range_min
&&
183 reg
<= rt5640_ranges
[i
].range_max
))
189 case RT5640_EQ_CTRL1
:
190 case RT5640_DRC_AGC_1
:
191 case RT5640_ANC_CTRL1
:
192 case RT5640_IRQ_CTRL2
:
193 case RT5640_INT_IRQ_ST
:
194 case RT5640_DSP_CTRL2
:
195 case RT5640_DSP_CTRL3
:
196 case RT5640_PRIV_INDEX
:
197 case RT5640_PRIV_DATA
:
198 case RT5640_PGM_REG_ARR1
:
199 case RT5640_PGM_REG_ARR3
:
200 case RT5640_VENDOR_ID
:
201 case RT5640_VENDOR_ID1
:
202 case RT5640_VENDOR_ID2
:
209 static bool rt5640_readable_register(struct device
*dev
, unsigned int reg
)
213 for (i
= 0; i
< ARRAY_SIZE(rt5640_ranges
); i
++)
214 if ((reg
>= rt5640_ranges
[i
].window_start
&&
215 reg
<= rt5640_ranges
[i
].window_start
+
216 rt5640_ranges
[i
].window_len
) ||
217 (reg
>= rt5640_ranges
[i
].range_min
&&
218 reg
<= rt5640_ranges
[i
].range_max
))
226 case RT5640_MONO_OUT
:
229 case RT5640_INL_INR_VOL
:
230 case RT5640_DAC1_DIG_VOL
:
231 case RT5640_DAC2_DIG_VOL
:
232 case RT5640_DAC2_CTRL
:
233 case RT5640_ADC_DIG_VOL
:
234 case RT5640_ADC_DATA
:
235 case RT5640_ADC_BST_VOL
:
236 case RT5640_STO_ADC_MIXER
:
237 case RT5640_MONO_ADC_MIXER
:
238 case RT5640_AD_DA_MIXER
:
239 case RT5640_STO_DAC_MIXER
:
240 case RT5640_MONO_DAC_MIXER
:
241 case RT5640_DIG_MIXER
:
242 case RT5640_DSP_PATH1
:
243 case RT5640_DSP_PATH2
:
244 case RT5640_DIG_INF_DATA
:
245 case RT5640_REC_L1_MIXER
:
246 case RT5640_REC_L2_MIXER
:
247 case RT5640_REC_R1_MIXER
:
248 case RT5640_REC_R2_MIXER
:
249 case RT5640_HPO_MIXER
:
250 case RT5640_SPK_L_MIXER
:
251 case RT5640_SPK_R_MIXER
:
252 case RT5640_SPO_L_MIXER
:
253 case RT5640_SPO_R_MIXER
:
254 case RT5640_SPO_CLSD_RATIO
:
255 case RT5640_MONO_MIXER
:
256 case RT5640_OUT_L1_MIXER
:
257 case RT5640_OUT_L2_MIXER
:
258 case RT5640_OUT_L3_MIXER
:
259 case RT5640_OUT_R1_MIXER
:
260 case RT5640_OUT_R2_MIXER
:
261 case RT5640_OUT_R3_MIXER
:
262 case RT5640_LOUT_MIXER
:
263 case RT5640_PWR_DIG1
:
264 case RT5640_PWR_DIG2
:
265 case RT5640_PWR_ANLG1
:
266 case RT5640_PWR_ANLG2
:
267 case RT5640_PWR_MIXER
:
269 case RT5640_PRIV_INDEX
:
270 case RT5640_PRIV_DATA
:
271 case RT5640_I2S1_SDP
:
272 case RT5640_I2S2_SDP
:
273 case RT5640_ADDA_CLK1
:
274 case RT5640_ADDA_CLK2
:
277 case RT5640_PLL_CTRL1
:
278 case RT5640_PLL_CTRL2
:
285 case RT5640_CLS_D_OVCD
:
286 case RT5640_CLS_D_OUT
:
287 case RT5640_DEPOP_M1
:
288 case RT5640_DEPOP_M2
:
289 case RT5640_DEPOP_M3
:
290 case RT5640_CHARGE_PUMP
:
291 case RT5640_PV_DET_SPK_G
:
293 case RT5640_EQ_CTRL1
:
294 case RT5640_EQ_CTRL2
:
295 case RT5640_WIND_FILTER
:
296 case RT5640_DRC_AGC_1
:
297 case RT5640_DRC_AGC_2
:
298 case RT5640_DRC_AGC_3
:
300 case RT5640_ANC_CTRL1
:
301 case RT5640_ANC_CTRL2
:
302 case RT5640_ANC_CTRL3
:
305 case RT5640_IRQ_CTRL1
:
306 case RT5640_IRQ_CTRL2
:
307 case RT5640_INT_IRQ_ST
:
308 case RT5640_GPIO_CTRL1
:
309 case RT5640_GPIO_CTRL2
:
310 case RT5640_GPIO_CTRL3
:
311 case RT5640_DSP_CTRL1
:
312 case RT5640_DSP_CTRL2
:
313 case RT5640_DSP_CTRL3
:
314 case RT5640_DSP_CTRL4
:
315 case RT5640_PGM_REG_ARR1
:
316 case RT5640_PGM_REG_ARR2
:
317 case RT5640_PGM_REG_ARR3
:
318 case RT5640_PGM_REG_ARR4
:
319 case RT5640_PGM_REG_ARR5
:
320 case RT5640_SCB_FUNC
:
321 case RT5640_SCB_CTRL
:
322 case RT5640_BASE_BACK
:
323 case RT5640_MP3_PLUS1
:
324 case RT5640_MP3_PLUS2
:
327 case RT5640_HP_CALIB_AMP_DET
:
328 case RT5640_HP_CALIB2
:
334 case RT5640_VENDOR_ID
:
335 case RT5640_VENDOR_ID1
:
336 case RT5640_VENDOR_ID2
:
343 static const DECLARE_TLV_DB_SCALE(out_vol_tlv
, -4650, 150, 0);
344 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv
, -65625, 375, 0);
345 static const DECLARE_TLV_DB_SCALE(in_vol_tlv
, -3450, 150, 0);
346 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv
, -17625, 375, 0);
347 static const DECLARE_TLV_DB_SCALE(adc_bst_tlv
, 0, 1200, 0);
349 /* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
350 static unsigned int bst_tlv
[] = {
351 TLV_DB_RANGE_HEAD(7),
352 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
353 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
354 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
355 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
356 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
357 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
358 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0),
361 /* Interface data select */
362 static const char * const rt5640_data_select
[] = {
363 "Normal", "left copy to right", "right copy to left", "Swap"};
365 static SOC_ENUM_SINGLE_DECL(rt5640_if1_dac_enum
, RT5640_DIG_INF_DATA
,
366 RT5640_IF1_DAC_SEL_SFT
, rt5640_data_select
);
368 static SOC_ENUM_SINGLE_DECL(rt5640_if1_adc_enum
, RT5640_DIG_INF_DATA
,
369 RT5640_IF1_ADC_SEL_SFT
, rt5640_data_select
);
371 static SOC_ENUM_SINGLE_DECL(rt5640_if2_dac_enum
, RT5640_DIG_INF_DATA
,
372 RT5640_IF2_DAC_SEL_SFT
, rt5640_data_select
);
374 static SOC_ENUM_SINGLE_DECL(rt5640_if2_adc_enum
, RT5640_DIG_INF_DATA
,
375 RT5640_IF2_ADC_SEL_SFT
, rt5640_data_select
);
377 /* Class D speaker gain ratio */
378 static const char * const rt5640_clsd_spk_ratio
[] = {"1.66x", "1.83x", "1.94x",
379 "2x", "2.11x", "2.22x", "2.33x", "2.44x", "2.55x", "2.66x", "2.77x"};
381 static SOC_ENUM_SINGLE_DECL(rt5640_clsd_spk_ratio_enum
, RT5640_CLS_D_OUT
,
382 RT5640_CLSD_RATIO_SFT
, rt5640_clsd_spk_ratio
);
384 static const struct snd_kcontrol_new rt5640_snd_controls
[] = {
385 /* Speaker Output Volume */
386 SOC_DOUBLE("Speaker Channel Switch", RT5640_SPK_VOL
,
387 RT5640_VOL_L_SFT
, RT5640_VOL_R_SFT
, 1, 1),
388 SOC_DOUBLE_TLV("Speaker Playback Volume", RT5640_SPK_VOL
,
389 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
, 39, 1, out_vol_tlv
),
390 /* Headphone Output Volume */
391 SOC_DOUBLE("HP Channel Switch", RT5640_HP_VOL
,
392 RT5640_VOL_L_SFT
, RT5640_VOL_R_SFT
, 1, 1),
393 SOC_DOUBLE_TLV("HP Playback Volume", RT5640_HP_VOL
,
394 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
, 39, 1, out_vol_tlv
),
396 SOC_DOUBLE("OUT Playback Switch", RT5640_OUTPUT
,
397 RT5640_L_MUTE_SFT
, RT5640_R_MUTE_SFT
, 1, 1),
398 SOC_DOUBLE("OUT Channel Switch", RT5640_OUTPUT
,
399 RT5640_VOL_L_SFT
, RT5640_VOL_R_SFT
, 1, 1),
400 SOC_DOUBLE_TLV("OUT Playback Volume", RT5640_OUTPUT
,
401 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
, 39, 1, out_vol_tlv
),
403 /* DAC Digital Volume */
404 SOC_DOUBLE("DAC2 Playback Switch", RT5640_DAC2_CTRL
,
405 RT5640_M_DAC_L2_VOL_SFT
, RT5640_M_DAC_R2_VOL_SFT
, 1, 1),
406 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5640_DAC1_DIG_VOL
,
407 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
,
408 175, 0, dac_vol_tlv
),
409 /* IN1/IN2 Control */
410 SOC_SINGLE_TLV("IN1 Boost", RT5640_IN1_IN2
,
411 RT5640_BST_SFT1
, 8, 0, bst_tlv
),
412 SOC_SINGLE_TLV("IN2 Boost", RT5640_IN3_IN4
,
413 RT5640_BST_SFT2
, 8, 0, bst_tlv
),
414 /* INL/INR Volume Control */
415 SOC_DOUBLE_TLV("IN Capture Volume", RT5640_INL_INR_VOL
,
416 RT5640_INL_VOL_SFT
, RT5640_INR_VOL_SFT
,
418 /* ADC Digital Volume Control */
419 SOC_DOUBLE("ADC Capture Switch", RT5640_ADC_DIG_VOL
,
420 RT5640_L_MUTE_SFT
, RT5640_R_MUTE_SFT
, 1, 1),
421 SOC_DOUBLE_TLV("ADC Capture Volume", RT5640_ADC_DIG_VOL
,
422 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
,
423 127, 0, adc_vol_tlv
),
424 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5640_ADC_DATA
,
425 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
,
426 127, 0, adc_vol_tlv
),
427 /* ADC Boost Volume Control */
428 SOC_DOUBLE_TLV("ADC Boost Gain", RT5640_ADC_BST_VOL
,
429 RT5640_ADC_L_BST_SFT
, RT5640_ADC_R_BST_SFT
,
431 /* Class D speaker gain ratio */
432 SOC_ENUM("Class D SPK Ratio Control", rt5640_clsd_spk_ratio_enum
),
434 SOC_ENUM("ADC IF1 Data Switch", rt5640_if1_adc_enum
),
435 SOC_ENUM("DAC IF1 Data Switch", rt5640_if1_dac_enum
),
436 SOC_ENUM("ADC IF2 Data Switch", rt5640_if2_adc_enum
),
437 SOC_ENUM("DAC IF2 Data Switch", rt5640_if2_dac_enum
),
440 static const struct snd_kcontrol_new rt5640_specific_snd_controls
[] = {
441 /* MONO Output Control */
442 SOC_SINGLE("Mono Playback Switch", RT5640_MONO_OUT
, RT5640_L_MUTE_SFT
,
445 SOC_DOUBLE_TLV("Mono DAC Playback Volume", RT5640_DAC2_DIG_VOL
,
446 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
, 175, 0, dac_vol_tlv
),
450 * set_dmic_clk - Set parameter of dmic.
453 * @kcontrol: The kcontrol of this widget.
457 static int set_dmic_clk(struct snd_soc_dapm_widget
*w
,
458 struct snd_kcontrol
*kcontrol
, int event
)
460 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
461 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
464 idx
= rl6231_calc_dmic_clk(rt5640
->sysclk
);
467 dev_err(codec
->dev
, "Failed to set DMIC clock\n");
469 snd_soc_update_bits(codec
, RT5640_DMIC
, RT5640_DMIC_CLK_MASK
,
470 idx
<< RT5640_DMIC_CLK_SFT
);
474 static int is_sys_clk_from_pll(struct snd_soc_dapm_widget
*source
,
475 struct snd_soc_dapm_widget
*sink
)
477 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(source
->dapm
);
480 val
= snd_soc_read(codec
, RT5640_GLB_CLK
);
481 val
&= RT5640_SCLK_SRC_MASK
;
482 if (val
== RT5640_SCLK_SRC_PLL1
)
489 static const struct snd_kcontrol_new rt5640_sto_adc_l_mix
[] = {
490 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_STO_ADC_MIXER
,
491 RT5640_M_ADC_L1_SFT
, 1, 1),
492 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_STO_ADC_MIXER
,
493 RT5640_M_ADC_L2_SFT
, 1, 1),
496 static const struct snd_kcontrol_new rt5640_sto_adc_r_mix
[] = {
497 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_STO_ADC_MIXER
,
498 RT5640_M_ADC_R1_SFT
, 1, 1),
499 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_STO_ADC_MIXER
,
500 RT5640_M_ADC_R2_SFT
, 1, 1),
503 static const struct snd_kcontrol_new rt5640_mono_adc_l_mix
[] = {
504 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_MONO_ADC_MIXER
,
505 RT5640_M_MONO_ADC_L1_SFT
, 1, 1),
506 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_MONO_ADC_MIXER
,
507 RT5640_M_MONO_ADC_L2_SFT
, 1, 1),
510 static const struct snd_kcontrol_new rt5640_mono_adc_r_mix
[] = {
511 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_MONO_ADC_MIXER
,
512 RT5640_M_MONO_ADC_R1_SFT
, 1, 1),
513 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_MONO_ADC_MIXER
,
514 RT5640_M_MONO_ADC_R2_SFT
, 1, 1),
517 static const struct snd_kcontrol_new rt5640_dac_l_mix
[] = {
518 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5640_AD_DA_MIXER
,
519 RT5640_M_ADCMIX_L_SFT
, 1, 1),
520 SOC_DAPM_SINGLE("INF1 Switch", RT5640_AD_DA_MIXER
,
521 RT5640_M_IF1_DAC_L_SFT
, 1, 1),
524 static const struct snd_kcontrol_new rt5640_dac_r_mix
[] = {
525 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5640_AD_DA_MIXER
,
526 RT5640_M_ADCMIX_R_SFT
, 1, 1),
527 SOC_DAPM_SINGLE("INF1 Switch", RT5640_AD_DA_MIXER
,
528 RT5640_M_IF1_DAC_R_SFT
, 1, 1),
531 static const struct snd_kcontrol_new rt5640_sto_dac_l_mix
[] = {
532 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_STO_DAC_MIXER
,
533 RT5640_M_DAC_L1_SFT
, 1, 1),
534 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_STO_DAC_MIXER
,
535 RT5640_M_DAC_L2_SFT
, 1, 1),
536 SOC_DAPM_SINGLE("ANC Switch", RT5640_STO_DAC_MIXER
,
537 RT5640_M_ANC_DAC_L_SFT
, 1, 1),
540 static const struct snd_kcontrol_new rt5640_sto_dac_r_mix
[] = {
541 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_STO_DAC_MIXER
,
542 RT5640_M_DAC_R1_SFT
, 1, 1),
543 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_STO_DAC_MIXER
,
544 RT5640_M_DAC_R2_SFT
, 1, 1),
545 SOC_DAPM_SINGLE("ANC Switch", RT5640_STO_DAC_MIXER
,
546 RT5640_M_ANC_DAC_R_SFT
, 1, 1),
549 static const struct snd_kcontrol_new rt5639_sto_dac_l_mix
[] = {
550 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_STO_DAC_MIXER
,
551 RT5640_M_DAC_L1_SFT
, 1, 1),
552 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_STO_DAC_MIXER
,
553 RT5640_M_DAC_L2_SFT
, 1, 1),
556 static const struct snd_kcontrol_new rt5639_sto_dac_r_mix
[] = {
557 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_STO_DAC_MIXER
,
558 RT5640_M_DAC_R1_SFT
, 1, 1),
559 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_STO_DAC_MIXER
,
560 RT5640_M_DAC_R2_SFT
, 1, 1),
563 static const struct snd_kcontrol_new rt5640_mono_dac_l_mix
[] = {
564 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_MONO_DAC_MIXER
,
565 RT5640_M_DAC_L1_MONO_L_SFT
, 1, 1),
566 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_MONO_DAC_MIXER
,
567 RT5640_M_DAC_L2_MONO_L_SFT
, 1, 1),
568 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_MONO_DAC_MIXER
,
569 RT5640_M_DAC_R2_MONO_L_SFT
, 1, 1),
572 static const struct snd_kcontrol_new rt5640_mono_dac_r_mix
[] = {
573 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_MONO_DAC_MIXER
,
574 RT5640_M_DAC_R1_MONO_R_SFT
, 1, 1),
575 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_MONO_DAC_MIXER
,
576 RT5640_M_DAC_R2_MONO_R_SFT
, 1, 1),
577 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_MONO_DAC_MIXER
,
578 RT5640_M_DAC_L2_MONO_R_SFT
, 1, 1),
581 static const struct snd_kcontrol_new rt5640_dig_l_mix
[] = {
582 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_DIG_MIXER
,
583 RT5640_M_STO_L_DAC_L_SFT
, 1, 1),
584 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_DIG_MIXER
,
585 RT5640_M_DAC_L2_DAC_L_SFT
, 1, 1),
588 static const struct snd_kcontrol_new rt5640_dig_r_mix
[] = {
589 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_DIG_MIXER
,
590 RT5640_M_STO_R_DAC_R_SFT
, 1, 1),
591 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_DIG_MIXER
,
592 RT5640_M_DAC_R2_DAC_R_SFT
, 1, 1),
595 /* Analog Input Mixer */
596 static const struct snd_kcontrol_new rt5640_rec_l_mix
[] = {
597 SOC_DAPM_SINGLE("HPOL Switch", RT5640_REC_L2_MIXER
,
598 RT5640_M_HP_L_RM_L_SFT
, 1, 1),
599 SOC_DAPM_SINGLE("INL Switch", RT5640_REC_L2_MIXER
,
600 RT5640_M_IN_L_RM_L_SFT
, 1, 1),
601 SOC_DAPM_SINGLE("BST2 Switch", RT5640_REC_L2_MIXER
,
602 RT5640_M_BST4_RM_L_SFT
, 1, 1),
603 SOC_DAPM_SINGLE("BST1 Switch", RT5640_REC_L2_MIXER
,
604 RT5640_M_BST1_RM_L_SFT
, 1, 1),
605 SOC_DAPM_SINGLE("OUT MIXL Switch", RT5640_REC_L2_MIXER
,
606 RT5640_M_OM_L_RM_L_SFT
, 1, 1),
609 static const struct snd_kcontrol_new rt5640_rec_r_mix
[] = {
610 SOC_DAPM_SINGLE("HPOR Switch", RT5640_REC_R2_MIXER
,
611 RT5640_M_HP_R_RM_R_SFT
, 1, 1),
612 SOC_DAPM_SINGLE("INR Switch", RT5640_REC_R2_MIXER
,
613 RT5640_M_IN_R_RM_R_SFT
, 1, 1),
614 SOC_DAPM_SINGLE("BST2 Switch", RT5640_REC_R2_MIXER
,
615 RT5640_M_BST4_RM_R_SFT
, 1, 1),
616 SOC_DAPM_SINGLE("BST1 Switch", RT5640_REC_R2_MIXER
,
617 RT5640_M_BST1_RM_R_SFT
, 1, 1),
618 SOC_DAPM_SINGLE("OUT MIXR Switch", RT5640_REC_R2_MIXER
,
619 RT5640_M_OM_R_RM_R_SFT
, 1, 1),
622 /* Analog Output Mixer */
623 static const struct snd_kcontrol_new rt5640_spk_l_mix
[] = {
624 SOC_DAPM_SINGLE("REC MIXL Switch", RT5640_SPK_L_MIXER
,
625 RT5640_M_RM_L_SM_L_SFT
, 1, 1),
626 SOC_DAPM_SINGLE("INL Switch", RT5640_SPK_L_MIXER
,
627 RT5640_M_IN_L_SM_L_SFT
, 1, 1),
628 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_SPK_L_MIXER
,
629 RT5640_M_DAC_L1_SM_L_SFT
, 1, 1),
630 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_SPK_L_MIXER
,
631 RT5640_M_DAC_L2_SM_L_SFT
, 1, 1),
632 SOC_DAPM_SINGLE("OUT MIXL Switch", RT5640_SPK_L_MIXER
,
633 RT5640_M_OM_L_SM_L_SFT
, 1, 1),
636 static const struct snd_kcontrol_new rt5640_spk_r_mix
[] = {
637 SOC_DAPM_SINGLE("REC MIXR Switch", RT5640_SPK_R_MIXER
,
638 RT5640_M_RM_R_SM_R_SFT
, 1, 1),
639 SOC_DAPM_SINGLE("INR Switch", RT5640_SPK_R_MIXER
,
640 RT5640_M_IN_R_SM_R_SFT
, 1, 1),
641 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_SPK_R_MIXER
,
642 RT5640_M_DAC_R1_SM_R_SFT
, 1, 1),
643 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_SPK_R_MIXER
,
644 RT5640_M_DAC_R2_SM_R_SFT
, 1, 1),
645 SOC_DAPM_SINGLE("OUT MIXR Switch", RT5640_SPK_R_MIXER
,
646 RT5640_M_OM_R_SM_R_SFT
, 1, 1),
649 static const struct snd_kcontrol_new rt5640_out_l_mix
[] = {
650 SOC_DAPM_SINGLE("SPK MIXL Switch", RT5640_OUT_L3_MIXER
,
651 RT5640_M_SM_L_OM_L_SFT
, 1, 1),
652 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_L3_MIXER
,
653 RT5640_M_BST1_OM_L_SFT
, 1, 1),
654 SOC_DAPM_SINGLE("INL Switch", RT5640_OUT_L3_MIXER
,
655 RT5640_M_IN_L_OM_L_SFT
, 1, 1),
656 SOC_DAPM_SINGLE("REC MIXL Switch", RT5640_OUT_L3_MIXER
,
657 RT5640_M_RM_L_OM_L_SFT
, 1, 1),
658 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_OUT_L3_MIXER
,
659 RT5640_M_DAC_R2_OM_L_SFT
, 1, 1),
660 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_OUT_L3_MIXER
,
661 RT5640_M_DAC_L2_OM_L_SFT
, 1, 1),
662 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_OUT_L3_MIXER
,
663 RT5640_M_DAC_L1_OM_L_SFT
, 1, 1),
666 static const struct snd_kcontrol_new rt5640_out_r_mix
[] = {
667 SOC_DAPM_SINGLE("SPK MIXR Switch", RT5640_OUT_R3_MIXER
,
668 RT5640_M_SM_L_OM_R_SFT
, 1, 1),
669 SOC_DAPM_SINGLE("BST2 Switch", RT5640_OUT_R3_MIXER
,
670 RT5640_M_BST4_OM_R_SFT
, 1, 1),
671 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_R3_MIXER
,
672 RT5640_M_BST1_OM_R_SFT
, 1, 1),
673 SOC_DAPM_SINGLE("INR Switch", RT5640_OUT_R3_MIXER
,
674 RT5640_M_IN_R_OM_R_SFT
, 1, 1),
675 SOC_DAPM_SINGLE("REC MIXR Switch", RT5640_OUT_R3_MIXER
,
676 RT5640_M_RM_R_OM_R_SFT
, 1, 1),
677 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_OUT_R3_MIXER
,
678 RT5640_M_DAC_L2_OM_R_SFT
, 1, 1),
679 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_OUT_R3_MIXER
,
680 RT5640_M_DAC_R2_OM_R_SFT
, 1, 1),
681 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_OUT_R3_MIXER
,
682 RT5640_M_DAC_R1_OM_R_SFT
, 1, 1),
685 static const struct snd_kcontrol_new rt5639_out_l_mix
[] = {
686 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_L3_MIXER
,
687 RT5640_M_BST1_OM_L_SFT
, 1, 1),
688 SOC_DAPM_SINGLE("INL Switch", RT5640_OUT_L3_MIXER
,
689 RT5640_M_IN_L_OM_L_SFT
, 1, 1),
690 SOC_DAPM_SINGLE("REC MIXL Switch", RT5640_OUT_L3_MIXER
,
691 RT5640_M_RM_L_OM_L_SFT
, 1, 1),
692 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_OUT_L3_MIXER
,
693 RT5640_M_DAC_L1_OM_L_SFT
, 1, 1),
696 static const struct snd_kcontrol_new rt5639_out_r_mix
[] = {
697 SOC_DAPM_SINGLE("BST2 Switch", RT5640_OUT_R3_MIXER
,
698 RT5640_M_BST4_OM_R_SFT
, 1, 1),
699 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_R3_MIXER
,
700 RT5640_M_BST1_OM_R_SFT
, 1, 1),
701 SOC_DAPM_SINGLE("INR Switch", RT5640_OUT_R3_MIXER
,
702 RT5640_M_IN_R_OM_R_SFT
, 1, 1),
703 SOC_DAPM_SINGLE("REC MIXR Switch", RT5640_OUT_R3_MIXER
,
704 RT5640_M_RM_R_OM_R_SFT
, 1, 1),
705 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_OUT_R3_MIXER
,
706 RT5640_M_DAC_R1_OM_R_SFT
, 1, 1),
709 static const struct snd_kcontrol_new rt5640_spo_l_mix
[] = {
710 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_SPO_L_MIXER
,
711 RT5640_M_DAC_R1_SPM_L_SFT
, 1, 1),
712 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_SPO_L_MIXER
,
713 RT5640_M_DAC_L1_SPM_L_SFT
, 1, 1),
714 SOC_DAPM_SINGLE("SPKVOL R Switch", RT5640_SPO_L_MIXER
,
715 RT5640_M_SV_R_SPM_L_SFT
, 1, 1),
716 SOC_DAPM_SINGLE("SPKVOL L Switch", RT5640_SPO_L_MIXER
,
717 RT5640_M_SV_L_SPM_L_SFT
, 1, 1),
718 SOC_DAPM_SINGLE("BST1 Switch", RT5640_SPO_L_MIXER
,
719 RT5640_M_BST1_SPM_L_SFT
, 1, 1),
722 static const struct snd_kcontrol_new rt5640_spo_r_mix
[] = {
723 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_SPO_R_MIXER
,
724 RT5640_M_DAC_R1_SPM_R_SFT
, 1, 1),
725 SOC_DAPM_SINGLE("SPKVOL R Switch", RT5640_SPO_R_MIXER
,
726 RT5640_M_SV_R_SPM_R_SFT
, 1, 1),
727 SOC_DAPM_SINGLE("BST1 Switch", RT5640_SPO_R_MIXER
,
728 RT5640_M_BST1_SPM_R_SFT
, 1, 1),
731 static const struct snd_kcontrol_new rt5640_hpo_mix
[] = {
732 SOC_DAPM_SINGLE("HPO MIX DAC2 Switch", RT5640_HPO_MIXER
,
733 RT5640_M_DAC2_HM_SFT
, 1, 1),
734 SOC_DAPM_SINGLE("HPO MIX DAC1 Switch", RT5640_HPO_MIXER
,
735 RT5640_M_DAC1_HM_SFT
, 1, 1),
736 SOC_DAPM_SINGLE("HPO MIX HPVOL Switch", RT5640_HPO_MIXER
,
737 RT5640_M_HPVOL_HM_SFT
, 1, 1),
740 static const struct snd_kcontrol_new rt5639_hpo_mix
[] = {
741 SOC_DAPM_SINGLE("HPO MIX DAC1 Switch", RT5640_HPO_MIXER
,
742 RT5640_M_DAC1_HM_SFT
, 1, 1),
743 SOC_DAPM_SINGLE("HPO MIX HPVOL Switch", RT5640_HPO_MIXER
,
744 RT5640_M_HPVOL_HM_SFT
, 1, 1),
747 static const struct snd_kcontrol_new rt5640_lout_mix
[] = {
748 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_LOUT_MIXER
,
749 RT5640_M_DAC_L1_LM_SFT
, 1, 1),
750 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_LOUT_MIXER
,
751 RT5640_M_DAC_R1_LM_SFT
, 1, 1),
752 SOC_DAPM_SINGLE("OUTVOL L Switch", RT5640_LOUT_MIXER
,
753 RT5640_M_OV_L_LM_SFT
, 1, 1),
754 SOC_DAPM_SINGLE("OUTVOL R Switch", RT5640_LOUT_MIXER
,
755 RT5640_M_OV_R_LM_SFT
, 1, 1),
758 static const struct snd_kcontrol_new rt5640_mono_mix
[] = {
759 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_MONO_MIXER
,
760 RT5640_M_DAC_R2_MM_SFT
, 1, 1),
761 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_MONO_MIXER
,
762 RT5640_M_DAC_L2_MM_SFT
, 1, 1),
763 SOC_DAPM_SINGLE("OUTVOL R Switch", RT5640_MONO_MIXER
,
764 RT5640_M_OV_R_MM_SFT
, 1, 1),
765 SOC_DAPM_SINGLE("OUTVOL L Switch", RT5640_MONO_MIXER
,
766 RT5640_M_OV_L_MM_SFT
, 1, 1),
767 SOC_DAPM_SINGLE("BST1 Switch", RT5640_MONO_MIXER
,
768 RT5640_M_BST1_MM_SFT
, 1, 1),
771 static const struct snd_kcontrol_new spk_l_enable_control
=
772 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_SPK_VOL
,
773 RT5640_L_MUTE_SFT
, 1, 1);
775 static const struct snd_kcontrol_new spk_r_enable_control
=
776 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_SPK_VOL
,
777 RT5640_R_MUTE_SFT
, 1, 1);
779 static const struct snd_kcontrol_new hp_l_enable_control
=
780 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_HP_VOL
,
781 RT5640_L_MUTE_SFT
, 1, 1);
783 static const struct snd_kcontrol_new hp_r_enable_control
=
784 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_HP_VOL
,
785 RT5640_R_MUTE_SFT
, 1, 1);
787 /* Stereo ADC source */
788 static const char * const rt5640_stereo_adc1_src
[] = {
792 static SOC_ENUM_SINGLE_DECL(rt5640_stereo_adc1_enum
, RT5640_STO_ADC_MIXER
,
793 RT5640_ADC_1_SRC_SFT
, rt5640_stereo_adc1_src
);
795 static const struct snd_kcontrol_new rt5640_sto_adc_1_mux
=
796 SOC_DAPM_ENUM("Stereo ADC1 Mux", rt5640_stereo_adc1_enum
);
798 static const char * const rt5640_stereo_adc2_src
[] = {
799 "DMIC1", "DMIC2", "DIG MIX"
802 static SOC_ENUM_SINGLE_DECL(rt5640_stereo_adc2_enum
, RT5640_STO_ADC_MIXER
,
803 RT5640_ADC_2_SRC_SFT
, rt5640_stereo_adc2_src
);
805 static const struct snd_kcontrol_new rt5640_sto_adc_2_mux
=
806 SOC_DAPM_ENUM("Stereo ADC2 Mux", rt5640_stereo_adc2_enum
);
808 /* Mono ADC source */
809 static const char * const rt5640_mono_adc_l1_src
[] = {
810 "Mono DAC MIXL", "ADCL"
813 static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_l1_enum
, RT5640_MONO_ADC_MIXER
,
814 RT5640_MONO_ADC_L1_SRC_SFT
, rt5640_mono_adc_l1_src
);
816 static const struct snd_kcontrol_new rt5640_mono_adc_l1_mux
=
817 SOC_DAPM_ENUM("Mono ADC1 left source", rt5640_mono_adc_l1_enum
);
819 static const char * const rt5640_mono_adc_l2_src
[] = {
820 "DMIC L1", "DMIC L2", "Mono DAC MIXL"
823 static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_l2_enum
, RT5640_MONO_ADC_MIXER
,
824 RT5640_MONO_ADC_L2_SRC_SFT
, rt5640_mono_adc_l2_src
);
826 static const struct snd_kcontrol_new rt5640_mono_adc_l2_mux
=
827 SOC_DAPM_ENUM("Mono ADC2 left source", rt5640_mono_adc_l2_enum
);
829 static const char * const rt5640_mono_adc_r1_src
[] = {
830 "Mono DAC MIXR", "ADCR"
833 static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_r1_enum
, RT5640_MONO_ADC_MIXER
,
834 RT5640_MONO_ADC_R1_SRC_SFT
, rt5640_mono_adc_r1_src
);
836 static const struct snd_kcontrol_new rt5640_mono_adc_r1_mux
=
837 SOC_DAPM_ENUM("Mono ADC1 right source", rt5640_mono_adc_r1_enum
);
839 static const char * const rt5640_mono_adc_r2_src
[] = {
840 "DMIC R1", "DMIC R2", "Mono DAC MIXR"
843 static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_r2_enum
, RT5640_MONO_ADC_MIXER
,
844 RT5640_MONO_ADC_R2_SRC_SFT
, rt5640_mono_adc_r2_src
);
846 static const struct snd_kcontrol_new rt5640_mono_adc_r2_mux
=
847 SOC_DAPM_ENUM("Mono ADC2 right source", rt5640_mono_adc_r2_enum
);
849 /* DAC2 channel source */
850 static const char * const rt5640_dac_l2_src
[] = {
854 static int rt5640_dac_l2_values
[] = {
859 static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dac_l2_enum
,
860 RT5640_DSP_PATH2
, RT5640_DAC_L2_SEL_SFT
,
861 0x3, rt5640_dac_l2_src
, rt5640_dac_l2_values
);
863 static const struct snd_kcontrol_new rt5640_dac_l2_mux
=
864 SOC_DAPM_ENUM("DAC2 left channel source", rt5640_dac_l2_enum
);
866 static const char * const rt5640_dac_r2_src
[] = {
870 static int rt5640_dac_r2_values
[] = {
874 static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dac_r2_enum
,
875 RT5640_DSP_PATH2
, RT5640_DAC_R2_SEL_SFT
,
876 0x3, rt5640_dac_r2_src
, rt5640_dac_r2_values
);
878 static const struct snd_kcontrol_new rt5640_dac_r2_mux
=
879 SOC_DAPM_ENUM("DAC2 right channel source", rt5640_dac_r2_enum
);
881 /* digital interface and iis interface map */
882 static const char * const rt5640_dai_iis_map
[] = {
883 "1:1|2:2", "1:2|2:1", "1:1|2:1", "1:2|2:2"
886 static int rt5640_dai_iis_map_values
[] = {
893 static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dai_iis_map_enum
,
894 RT5640_I2S1_SDP
, RT5640_I2S_IF_SFT
,
895 0x7, rt5640_dai_iis_map
,
896 rt5640_dai_iis_map_values
);
898 static const struct snd_kcontrol_new rt5640_dai_mux
=
899 SOC_DAPM_ENUM("DAI select", rt5640_dai_iis_map_enum
);
902 static const char * const rt5640_sdi_sel
[] = {
906 static SOC_ENUM_SINGLE_DECL(rt5640_sdi_sel_enum
, RT5640_I2S2_SDP
,
907 RT5640_I2S2_SDI_SFT
, rt5640_sdi_sel
);
909 static const struct snd_kcontrol_new rt5640_sdi_mux
=
910 SOC_DAPM_ENUM("SDI select", rt5640_sdi_sel_enum
);
912 static void hp_amp_power_on(struct snd_soc_codec
*codec
)
914 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
916 /* depop parameters */
917 regmap_update_bits(rt5640
->regmap
, RT5640_PR_BASE
+
918 RT5640_CHPUMP_INT_REG1
, 0x0700, 0x0200);
919 regmap_update_bits(rt5640
->regmap
, RT5640_DEPOP_M2
,
920 RT5640_DEPOP_MASK
, RT5640_DEPOP_MAN
);
921 regmap_update_bits(rt5640
->regmap
, RT5640_DEPOP_M1
,
922 RT5640_HP_CP_MASK
| RT5640_HP_SG_MASK
| RT5640_HP_CB_MASK
,
923 RT5640_HP_CP_PU
| RT5640_HP_SG_DIS
| RT5640_HP_CB_PU
);
924 regmap_write(rt5640
->regmap
, RT5640_PR_BASE
+ RT5640_HP_DCC_INT1
,
926 /* headphone amp power on */
927 regmap_update_bits(rt5640
->regmap
, RT5640_PWR_ANLG1
,
928 RT5640_PWR_FV1
| RT5640_PWR_FV2
, 0);
929 regmap_update_bits(rt5640
->regmap
, RT5640_PWR_ANLG1
,
932 usleep_range(10000, 15000);
933 regmap_update_bits(rt5640
->regmap
, RT5640_PWR_ANLG1
,
934 RT5640_PWR_FV1
| RT5640_PWR_FV2
,
935 RT5640_PWR_FV1
| RT5640_PWR_FV2
);
938 static void rt5640_pmu_depop(struct snd_soc_codec
*codec
)
940 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
942 regmap_update_bits(rt5640
->regmap
, RT5640_DEPOP_M2
,
943 RT5640_DEPOP_MASK
| RT5640_DIG_DP_MASK
,
944 RT5640_DEPOP_AUTO
| RT5640_DIG_DP_EN
);
945 regmap_update_bits(rt5640
->regmap
, RT5640_CHARGE_PUMP
,
946 RT5640_PM_HP_MASK
, RT5640_PM_HP_HV
);
948 regmap_update_bits(rt5640
->regmap
, RT5640_DEPOP_M3
,
949 RT5640_CP_FQ1_MASK
| RT5640_CP_FQ2_MASK
| RT5640_CP_FQ3_MASK
,
950 (RT5640_CP_FQ_192_KHZ
<< RT5640_CP_FQ1_SFT
) |
951 (RT5640_CP_FQ_12_KHZ
<< RT5640_CP_FQ2_SFT
) |
952 (RT5640_CP_FQ_192_KHZ
<< RT5640_CP_FQ3_SFT
));
954 regmap_write(rt5640
->regmap
, RT5640_PR_BASE
+
955 RT5640_MAMP_INT_REG2
, 0x1c00);
956 regmap_update_bits(rt5640
->regmap
, RT5640_DEPOP_M1
,
957 RT5640_HP_CP_MASK
| RT5640_HP_SG_MASK
,
958 RT5640_HP_CP_PD
| RT5640_HP_SG_EN
);
959 regmap_update_bits(rt5640
->regmap
, RT5640_PR_BASE
+
960 RT5640_CHPUMP_INT_REG1
, 0x0700, 0x0400);
963 static int rt5640_hp_event(struct snd_soc_dapm_widget
*w
,
964 struct snd_kcontrol
*kcontrol
, int event
)
966 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
967 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
970 case SND_SOC_DAPM_POST_PMU
:
971 rt5640_pmu_depop(codec
);
975 case SND_SOC_DAPM_PRE_PMD
:
977 usleep_range(70000, 75000);
987 static int rt5640_hp_power_event(struct snd_soc_dapm_widget
*w
,
988 struct snd_kcontrol
*kcontrol
, int event
)
990 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
993 case SND_SOC_DAPM_POST_PMU
:
994 hp_amp_power_on(codec
);
1003 static int rt5640_hp_post_event(struct snd_soc_dapm_widget
*w
,
1004 struct snd_kcontrol
*kcontrol
, int event
)
1006 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1007 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1010 case SND_SOC_DAPM_POST_PMU
:
1011 if (!rt5640
->hp_mute
)
1012 usleep_range(80000, 85000);
1023 static const struct snd_soc_dapm_widget rt5640_dapm_widgets
[] = {
1024 SND_SOC_DAPM_SUPPLY("PLL1", RT5640_PWR_ANLG2
,
1025 RT5640_PWR_PLL_BIT
, 0, NULL
, 0),
1028 SND_SOC_DAPM_SUPPLY("LDO2", RT5640_PWR_ANLG1
,
1029 RT5640_PWR_LDO2_BIT
, 0, NULL
, 0),
1030 SND_SOC_DAPM_SUPPLY("MICBIAS1", RT5640_PWR_ANLG2
,
1031 RT5640_PWR_MB1_BIT
, 0, NULL
, 0),
1033 SND_SOC_DAPM_INPUT("DMIC1"),
1034 SND_SOC_DAPM_INPUT("DMIC2"),
1035 SND_SOC_DAPM_INPUT("IN1P"),
1036 SND_SOC_DAPM_INPUT("IN1N"),
1037 SND_SOC_DAPM_INPUT("IN2P"),
1038 SND_SOC_DAPM_INPUT("IN2N"),
1039 SND_SOC_DAPM_PGA("DMIC L1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1040 SND_SOC_DAPM_PGA("DMIC R1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1041 SND_SOC_DAPM_PGA("DMIC L2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1042 SND_SOC_DAPM_PGA("DMIC R2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1044 SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM
, 0, 0,
1045 set_dmic_clk
, SND_SOC_DAPM_PRE_PMU
),
1046 SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5640_DMIC
, RT5640_DMIC_1_EN_SFT
, 0,
1048 SND_SOC_DAPM_SUPPLY("DMIC2 Power", RT5640_DMIC
, RT5640_DMIC_2_EN_SFT
, 0,
1051 SND_SOC_DAPM_PGA("BST1", RT5640_PWR_ANLG2
,
1052 RT5640_PWR_BST1_BIT
, 0, NULL
, 0),
1053 SND_SOC_DAPM_PGA("BST2", RT5640_PWR_ANLG2
,
1054 RT5640_PWR_BST4_BIT
, 0, NULL
, 0),
1056 SND_SOC_DAPM_PGA("INL VOL", RT5640_PWR_VOL
,
1057 RT5640_PWR_IN_L_BIT
, 0, NULL
, 0),
1058 SND_SOC_DAPM_PGA("INR VOL", RT5640_PWR_VOL
,
1059 RT5640_PWR_IN_R_BIT
, 0, NULL
, 0),
1061 SND_SOC_DAPM_MIXER("RECMIXL", RT5640_PWR_MIXER
, RT5640_PWR_RM_L_BIT
, 0,
1062 rt5640_rec_l_mix
, ARRAY_SIZE(rt5640_rec_l_mix
)),
1063 SND_SOC_DAPM_MIXER("RECMIXR", RT5640_PWR_MIXER
, RT5640_PWR_RM_R_BIT
, 0,
1064 rt5640_rec_r_mix
, ARRAY_SIZE(rt5640_rec_r_mix
)),
1066 SND_SOC_DAPM_ADC("ADC L", NULL
, RT5640_PWR_DIG1
,
1067 RT5640_PWR_ADC_L_BIT
, 0),
1068 SND_SOC_DAPM_ADC("ADC R", NULL
, RT5640_PWR_DIG1
,
1069 RT5640_PWR_ADC_R_BIT
, 0),
1071 SND_SOC_DAPM_MUX("Stereo ADC L2 Mux", SND_SOC_NOPM
, 0, 0,
1072 &rt5640_sto_adc_2_mux
),
1073 SND_SOC_DAPM_MUX("Stereo ADC R2 Mux", SND_SOC_NOPM
, 0, 0,
1074 &rt5640_sto_adc_2_mux
),
1075 SND_SOC_DAPM_MUX("Stereo ADC L1 Mux", SND_SOC_NOPM
, 0, 0,
1076 &rt5640_sto_adc_1_mux
),
1077 SND_SOC_DAPM_MUX("Stereo ADC R1 Mux", SND_SOC_NOPM
, 0, 0,
1078 &rt5640_sto_adc_1_mux
),
1079 SND_SOC_DAPM_MUX("Mono ADC L2 Mux", SND_SOC_NOPM
, 0, 0,
1080 &rt5640_mono_adc_l2_mux
),
1081 SND_SOC_DAPM_MUX("Mono ADC L1 Mux", SND_SOC_NOPM
, 0, 0,
1082 &rt5640_mono_adc_l1_mux
),
1083 SND_SOC_DAPM_MUX("Mono ADC R1 Mux", SND_SOC_NOPM
, 0, 0,
1084 &rt5640_mono_adc_r1_mux
),
1085 SND_SOC_DAPM_MUX("Mono ADC R2 Mux", SND_SOC_NOPM
, 0, 0,
1086 &rt5640_mono_adc_r2_mux
),
1088 SND_SOC_DAPM_SUPPLY("Stereo Filter", RT5640_PWR_DIG2
,
1089 RT5640_PWR_ADC_SF_BIT
, 0, NULL
, 0),
1090 SND_SOC_DAPM_MIXER("Stereo ADC MIXL", SND_SOC_NOPM
, 0, 0,
1091 rt5640_sto_adc_l_mix
, ARRAY_SIZE(rt5640_sto_adc_l_mix
)),
1092 SND_SOC_DAPM_MIXER("Stereo ADC MIXR", SND_SOC_NOPM
, 0, 0,
1093 rt5640_sto_adc_r_mix
, ARRAY_SIZE(rt5640_sto_adc_r_mix
)),
1094 SND_SOC_DAPM_SUPPLY("Mono Left Filter", RT5640_PWR_DIG2
,
1095 RT5640_PWR_ADC_MF_L_BIT
, 0, NULL
, 0),
1096 SND_SOC_DAPM_MIXER("Mono ADC MIXL", SND_SOC_NOPM
, 0, 0,
1097 rt5640_mono_adc_l_mix
, ARRAY_SIZE(rt5640_mono_adc_l_mix
)),
1098 SND_SOC_DAPM_SUPPLY("Mono Right Filter", RT5640_PWR_DIG2
,
1099 RT5640_PWR_ADC_MF_R_BIT
, 0, NULL
, 0),
1100 SND_SOC_DAPM_MIXER("Mono ADC MIXR", SND_SOC_NOPM
, 0, 0,
1101 rt5640_mono_adc_r_mix
, ARRAY_SIZE(rt5640_mono_adc_r_mix
)),
1103 /* Digital Interface */
1104 SND_SOC_DAPM_SUPPLY("I2S1", RT5640_PWR_DIG1
,
1105 RT5640_PWR_I2S1_BIT
, 0, NULL
, 0),
1106 SND_SOC_DAPM_PGA("IF1 DAC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1107 SND_SOC_DAPM_PGA("IF1 DAC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1108 SND_SOC_DAPM_PGA("IF1 DAC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1109 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1110 SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1111 SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1112 SND_SOC_DAPM_SUPPLY("I2S2", RT5640_PWR_DIG1
,
1113 RT5640_PWR_I2S2_BIT
, 0, NULL
, 0),
1114 SND_SOC_DAPM_PGA("IF2 DAC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1115 SND_SOC_DAPM_PGA("IF2 DAC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1116 SND_SOC_DAPM_PGA("IF2 DAC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1117 SND_SOC_DAPM_PGA("IF2 ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1118 SND_SOC_DAPM_PGA("IF2 ADC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1119 SND_SOC_DAPM_PGA("IF2 ADC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1120 /* Digital Interface Select */
1121 SND_SOC_DAPM_MUX("DAI1 RX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1122 SND_SOC_DAPM_MUX("DAI1 TX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1123 SND_SOC_DAPM_MUX("DAI1 IF1 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1124 SND_SOC_DAPM_MUX("DAI1 IF2 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1125 SND_SOC_DAPM_MUX("SDI1 TX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_sdi_mux
),
1126 SND_SOC_DAPM_MUX("DAI2 RX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1127 SND_SOC_DAPM_MUX("DAI2 TX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1128 SND_SOC_DAPM_MUX("DAI2 IF1 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1129 SND_SOC_DAPM_MUX("DAI2 IF2 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1130 SND_SOC_DAPM_MUX("SDI2 TX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_sdi_mux
),
1131 /* Audio Interface */
1132 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM
, 0, 0),
1133 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM
, 0, 0),
1134 SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Playback", 0, SND_SOC_NOPM
, 0, 0),
1135 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, SND_SOC_NOPM
, 0, 0),
1138 /* DAC mixer before sound effect */
1139 SND_SOC_DAPM_MIXER("DAC MIXL", SND_SOC_NOPM
, 0, 0,
1140 rt5640_dac_l_mix
, ARRAY_SIZE(rt5640_dac_l_mix
)),
1141 SND_SOC_DAPM_MIXER("DAC MIXR", SND_SOC_NOPM
, 0, 0,
1142 rt5640_dac_r_mix
, ARRAY_SIZE(rt5640_dac_r_mix
)),
1145 SND_SOC_DAPM_MIXER("Mono DAC MIXL", SND_SOC_NOPM
, 0, 0,
1146 rt5640_mono_dac_l_mix
, ARRAY_SIZE(rt5640_mono_dac_l_mix
)),
1147 SND_SOC_DAPM_MIXER("Mono DAC MIXR", SND_SOC_NOPM
, 0, 0,
1148 rt5640_mono_dac_r_mix
, ARRAY_SIZE(rt5640_mono_dac_r_mix
)),
1149 SND_SOC_DAPM_MIXER("DIG MIXL", SND_SOC_NOPM
, 0, 0,
1150 rt5640_dig_l_mix
, ARRAY_SIZE(rt5640_dig_l_mix
)),
1151 SND_SOC_DAPM_MIXER("DIG MIXR", SND_SOC_NOPM
, 0, 0,
1152 rt5640_dig_r_mix
, ARRAY_SIZE(rt5640_dig_r_mix
)),
1154 SND_SOC_DAPM_DAC("DAC L1", NULL
, RT5640_PWR_DIG1
,
1155 RT5640_PWR_DAC_L1_BIT
, 0),
1156 SND_SOC_DAPM_DAC("DAC R1", NULL
, RT5640_PWR_DIG1
,
1157 RT5640_PWR_DAC_R1_BIT
, 0),
1160 SND_SOC_DAPM_MIXER("SPK MIXL", RT5640_PWR_MIXER
, RT5640_PWR_SM_L_BIT
,
1161 0, rt5640_spk_l_mix
, ARRAY_SIZE(rt5640_spk_l_mix
)),
1162 SND_SOC_DAPM_MIXER("SPK MIXR", RT5640_PWR_MIXER
, RT5640_PWR_SM_R_BIT
,
1163 0, rt5640_spk_r_mix
, ARRAY_SIZE(rt5640_spk_r_mix
)),
1165 SND_SOC_DAPM_PGA("SPKVOL L", RT5640_PWR_VOL
,
1166 RT5640_PWR_SV_L_BIT
, 0, NULL
, 0),
1167 SND_SOC_DAPM_PGA("SPKVOL R", RT5640_PWR_VOL
,
1168 RT5640_PWR_SV_R_BIT
, 0, NULL
, 0),
1169 SND_SOC_DAPM_PGA("OUTVOL L", RT5640_PWR_VOL
,
1170 RT5640_PWR_OV_L_BIT
, 0, NULL
, 0),
1171 SND_SOC_DAPM_PGA("OUTVOL R", RT5640_PWR_VOL
,
1172 RT5640_PWR_OV_R_BIT
, 0, NULL
, 0),
1173 SND_SOC_DAPM_PGA("HPOVOL L", RT5640_PWR_VOL
,
1174 RT5640_PWR_HV_L_BIT
, 0, NULL
, 0),
1175 SND_SOC_DAPM_PGA("HPOVOL R", RT5640_PWR_VOL
,
1176 RT5640_PWR_HV_R_BIT
, 0, NULL
, 0),
1177 /* SPO/HPO/LOUT/Mono Mixer */
1178 SND_SOC_DAPM_MIXER("SPOL MIX", SND_SOC_NOPM
, 0,
1179 0, rt5640_spo_l_mix
, ARRAY_SIZE(rt5640_spo_l_mix
)),
1180 SND_SOC_DAPM_MIXER("SPOR MIX", SND_SOC_NOPM
, 0,
1181 0, rt5640_spo_r_mix
, ARRAY_SIZE(rt5640_spo_r_mix
)),
1182 SND_SOC_DAPM_MIXER("LOUT MIX", RT5640_PWR_ANLG1
, RT5640_PWR_LM_BIT
, 0,
1183 rt5640_lout_mix
, ARRAY_SIZE(rt5640_lout_mix
)),
1184 SND_SOC_DAPM_SUPPLY_S("Improve HP Amp Drv", 1, SND_SOC_NOPM
,
1185 0, 0, rt5640_hp_power_event
, SND_SOC_DAPM_POST_PMU
),
1186 SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM
, 0, 0,
1188 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
1189 SND_SOC_DAPM_SUPPLY("HP L Amp", RT5640_PWR_ANLG1
,
1190 RT5640_PWR_HP_L_BIT
, 0, NULL
, 0),
1191 SND_SOC_DAPM_SUPPLY("HP R Amp", RT5640_PWR_ANLG1
,
1192 RT5640_PWR_HP_R_BIT
, 0, NULL
, 0),
1193 SND_SOC_DAPM_SUPPLY("Improve SPK Amp Drv", RT5640_PWR_DIG1
,
1194 RT5640_PWR_CLS_D_BIT
, 0, NULL
, 0),
1197 SND_SOC_DAPM_SWITCH("Speaker L Playback", SND_SOC_NOPM
, 0, 0,
1198 &spk_l_enable_control
),
1199 SND_SOC_DAPM_SWITCH("Speaker R Playback", SND_SOC_NOPM
, 0, 0,
1200 &spk_r_enable_control
),
1201 SND_SOC_DAPM_SWITCH("HP L Playback", SND_SOC_NOPM
, 0, 0,
1202 &hp_l_enable_control
),
1203 SND_SOC_DAPM_SWITCH("HP R Playback", SND_SOC_NOPM
, 0, 0,
1204 &hp_r_enable_control
),
1205 SND_SOC_DAPM_POST("HP Post", rt5640_hp_post_event
),
1207 SND_SOC_DAPM_OUTPUT("SPOLP"),
1208 SND_SOC_DAPM_OUTPUT("SPOLN"),
1209 SND_SOC_DAPM_OUTPUT("SPORP"),
1210 SND_SOC_DAPM_OUTPUT("SPORN"),
1211 SND_SOC_DAPM_OUTPUT("HPOL"),
1212 SND_SOC_DAPM_OUTPUT("HPOR"),
1213 SND_SOC_DAPM_OUTPUT("LOUTL"),
1214 SND_SOC_DAPM_OUTPUT("LOUTR"),
1217 static const struct snd_soc_dapm_widget rt5640_specific_dapm_widgets
[] = {
1219 SND_SOC_DAPM_PGA("Audio DSP", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1221 SND_SOC_DAPM_PGA("ANC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1223 /* DAC2 channel Mux */
1224 SND_SOC_DAPM_MUX("DAC L2 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dac_l2_mux
),
1225 SND_SOC_DAPM_MUX("DAC R2 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dac_r2_mux
),
1227 SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM
, 0, 0,
1228 rt5640_sto_dac_l_mix
, ARRAY_SIZE(rt5640_sto_dac_l_mix
)),
1229 SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM
, 0, 0,
1230 rt5640_sto_dac_r_mix
, ARRAY_SIZE(rt5640_sto_dac_r_mix
)),
1232 SND_SOC_DAPM_DAC("DAC R2", NULL
, RT5640_PWR_DIG1
, RT5640_PWR_DAC_R2_BIT
,
1234 SND_SOC_DAPM_DAC("DAC L2", NULL
, RT5640_PWR_DIG1
, RT5640_PWR_DAC_L2_BIT
,
1237 SND_SOC_DAPM_MIXER("OUT MIXL", RT5640_PWR_MIXER
, RT5640_PWR_OM_L_BIT
,
1238 0, rt5640_out_l_mix
, ARRAY_SIZE(rt5640_out_l_mix
)),
1239 SND_SOC_DAPM_MIXER("OUT MIXR", RT5640_PWR_MIXER
, RT5640_PWR_OM_R_BIT
,
1240 0, rt5640_out_r_mix
, ARRAY_SIZE(rt5640_out_r_mix
)),
1242 SND_SOC_DAPM_MIXER("HPO MIX L", SND_SOC_NOPM
, 0, 0,
1243 rt5640_hpo_mix
, ARRAY_SIZE(rt5640_hpo_mix
)),
1244 SND_SOC_DAPM_MIXER("HPO MIX R", SND_SOC_NOPM
, 0, 0,
1245 rt5640_hpo_mix
, ARRAY_SIZE(rt5640_hpo_mix
)),
1247 SND_SOC_DAPM_MIXER("Mono MIX", RT5640_PWR_ANLG1
, RT5640_PWR_MM_BIT
, 0,
1248 rt5640_mono_mix
, ARRAY_SIZE(rt5640_mono_mix
)),
1249 SND_SOC_DAPM_SUPPLY("Improve MONO Amp Drv", RT5640_PWR_ANLG1
,
1250 RT5640_PWR_MA_BIT
, 0, NULL
, 0),
1252 SND_SOC_DAPM_OUTPUT("MONOP"),
1253 SND_SOC_DAPM_OUTPUT("MONON"),
1256 static const struct snd_soc_dapm_widget rt5639_specific_dapm_widgets
[] = {
1257 SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM
, 0, 0,
1258 rt5639_sto_dac_l_mix
, ARRAY_SIZE(rt5639_sto_dac_l_mix
)),
1259 SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM
, 0, 0,
1260 rt5639_sto_dac_r_mix
, ARRAY_SIZE(rt5639_sto_dac_r_mix
)),
1262 SND_SOC_DAPM_SUPPLY("DAC L2 Filter", RT5640_PWR_DIG1
,
1263 RT5640_PWR_DAC_L2_BIT
, 0, NULL
, 0),
1264 SND_SOC_DAPM_SUPPLY("DAC R2 Filter", RT5640_PWR_DIG1
,
1265 RT5640_PWR_DAC_R2_BIT
, 0, NULL
, 0),
1267 SND_SOC_DAPM_MIXER("OUT MIXL", RT5640_PWR_MIXER
, RT5640_PWR_OM_L_BIT
,
1268 0, rt5639_out_l_mix
, ARRAY_SIZE(rt5639_out_l_mix
)),
1269 SND_SOC_DAPM_MIXER("OUT MIXR", RT5640_PWR_MIXER
, RT5640_PWR_OM_R_BIT
,
1270 0, rt5639_out_r_mix
, ARRAY_SIZE(rt5639_out_r_mix
)),
1272 SND_SOC_DAPM_MIXER("HPO MIX L", SND_SOC_NOPM
, 0, 0,
1273 rt5639_hpo_mix
, ARRAY_SIZE(rt5639_hpo_mix
)),
1274 SND_SOC_DAPM_MIXER("HPO MIX R", SND_SOC_NOPM
, 0, 0,
1275 rt5639_hpo_mix
, ARRAY_SIZE(rt5639_hpo_mix
)),
1278 static const struct snd_soc_dapm_route rt5640_dapm_routes
[] = {
1279 {"IN1P", NULL
, "LDO2"},
1280 {"IN2P", NULL
, "LDO2"},
1282 {"DMIC L1", NULL
, "DMIC1"},
1283 {"DMIC R1", NULL
, "DMIC1"},
1284 {"DMIC L2", NULL
, "DMIC2"},
1285 {"DMIC R2", NULL
, "DMIC2"},
1287 {"BST1", NULL
, "IN1P"},
1288 {"BST1", NULL
, "IN1N"},
1289 {"BST2", NULL
, "IN2P"},
1290 {"BST2", NULL
, "IN2N"},
1292 {"INL VOL", NULL
, "IN2P"},
1293 {"INR VOL", NULL
, "IN2N"},
1295 {"RECMIXL", "HPOL Switch", "HPOL"},
1296 {"RECMIXL", "INL Switch", "INL VOL"},
1297 {"RECMIXL", "BST2 Switch", "BST2"},
1298 {"RECMIXL", "BST1 Switch", "BST1"},
1299 {"RECMIXL", "OUT MIXL Switch", "OUT MIXL"},
1301 {"RECMIXR", "HPOR Switch", "HPOR"},
1302 {"RECMIXR", "INR Switch", "INR VOL"},
1303 {"RECMIXR", "BST2 Switch", "BST2"},
1304 {"RECMIXR", "BST1 Switch", "BST1"},
1305 {"RECMIXR", "OUT MIXR Switch", "OUT MIXR"},
1307 {"ADC L", NULL
, "RECMIXL"},
1308 {"ADC R", NULL
, "RECMIXR"},
1310 {"DMIC L1", NULL
, "DMIC CLK"},
1311 {"DMIC L1", NULL
, "DMIC1 Power"},
1312 {"DMIC R1", NULL
, "DMIC CLK"},
1313 {"DMIC R1", NULL
, "DMIC1 Power"},
1314 {"DMIC L2", NULL
, "DMIC CLK"},
1315 {"DMIC L2", NULL
, "DMIC2 Power"},
1316 {"DMIC R2", NULL
, "DMIC CLK"},
1317 {"DMIC R2", NULL
, "DMIC2 Power"},
1319 {"Stereo ADC L2 Mux", "DMIC1", "DMIC L1"},
1320 {"Stereo ADC L2 Mux", "DMIC2", "DMIC L2"},
1321 {"Stereo ADC L2 Mux", "DIG MIX", "DIG MIXL"},
1322 {"Stereo ADC L1 Mux", "ADC", "ADC L"},
1323 {"Stereo ADC L1 Mux", "DIG MIX", "DIG MIXL"},
1325 {"Stereo ADC R1 Mux", "ADC", "ADC R"},
1326 {"Stereo ADC R1 Mux", "DIG MIX", "DIG MIXR"},
1327 {"Stereo ADC R2 Mux", "DMIC1", "DMIC R1"},
1328 {"Stereo ADC R2 Mux", "DMIC2", "DMIC R2"},
1329 {"Stereo ADC R2 Mux", "DIG MIX", "DIG MIXR"},
1331 {"Mono ADC L2 Mux", "DMIC L1", "DMIC L1"},
1332 {"Mono ADC L2 Mux", "DMIC L2", "DMIC L2"},
1333 {"Mono ADC L2 Mux", "Mono DAC MIXL", "Mono DAC MIXL"},
1334 {"Mono ADC L1 Mux", "Mono DAC MIXL", "Mono DAC MIXL"},
1335 {"Mono ADC L1 Mux", "ADCL", "ADC L"},
1337 {"Mono ADC R1 Mux", "Mono DAC MIXR", "Mono DAC MIXR"},
1338 {"Mono ADC R1 Mux", "ADCR", "ADC R"},
1339 {"Mono ADC R2 Mux", "DMIC R1", "DMIC R1"},
1340 {"Mono ADC R2 Mux", "DMIC R2", "DMIC R2"},
1341 {"Mono ADC R2 Mux", "Mono DAC MIXR", "Mono DAC MIXR"},
1343 {"Stereo ADC MIXL", "ADC1 Switch", "Stereo ADC L1 Mux"},
1344 {"Stereo ADC MIXL", "ADC2 Switch", "Stereo ADC L2 Mux"},
1345 {"Stereo ADC MIXL", NULL
, "Stereo Filter"},
1346 {"Stereo Filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1348 {"Stereo ADC MIXR", "ADC1 Switch", "Stereo ADC R1 Mux"},
1349 {"Stereo ADC MIXR", "ADC2 Switch", "Stereo ADC R2 Mux"},
1350 {"Stereo ADC MIXR", NULL
, "Stereo Filter"},
1351 {"Stereo Filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1353 {"Mono ADC MIXL", "ADC1 Switch", "Mono ADC L1 Mux"},
1354 {"Mono ADC MIXL", "ADC2 Switch", "Mono ADC L2 Mux"},
1355 {"Mono ADC MIXL", NULL
, "Mono Left Filter"},
1356 {"Mono Left Filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1358 {"Mono ADC MIXR", "ADC1 Switch", "Mono ADC R1 Mux"},
1359 {"Mono ADC MIXR", "ADC2 Switch", "Mono ADC R2 Mux"},
1360 {"Mono ADC MIXR", NULL
, "Mono Right Filter"},
1361 {"Mono Right Filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1363 {"IF2 ADC L", NULL
, "Mono ADC MIXL"},
1364 {"IF2 ADC R", NULL
, "Mono ADC MIXR"},
1365 {"IF1 ADC L", NULL
, "Stereo ADC MIXL"},
1366 {"IF1 ADC R", NULL
, "Stereo ADC MIXR"},
1368 {"IF1 ADC", NULL
, "I2S1"},
1369 {"IF1 ADC", NULL
, "IF1 ADC L"},
1370 {"IF1 ADC", NULL
, "IF1 ADC R"},
1371 {"IF2 ADC", NULL
, "I2S2"},
1372 {"IF2 ADC", NULL
, "IF2 ADC L"},
1373 {"IF2 ADC", NULL
, "IF2 ADC R"},
1375 {"DAI1 TX Mux", "1:1|2:2", "IF1 ADC"},
1376 {"DAI1 TX Mux", "1:2|2:1", "IF2 ADC"},
1377 {"DAI1 IF1 Mux", "1:1|2:1", "IF1 ADC"},
1378 {"DAI1 IF2 Mux", "1:1|2:1", "IF2 ADC"},
1379 {"SDI1 TX Mux", "IF1", "DAI1 IF1 Mux"},
1380 {"SDI1 TX Mux", "IF2", "DAI1 IF2 Mux"},
1382 {"DAI2 TX Mux", "1:2|2:1", "IF1 ADC"},
1383 {"DAI2 TX Mux", "1:1|2:2", "IF2 ADC"},
1384 {"DAI2 IF1 Mux", "1:2|2:2", "IF1 ADC"},
1385 {"DAI2 IF2 Mux", "1:2|2:2", "IF2 ADC"},
1386 {"SDI2 TX Mux", "IF1", "DAI2 IF1 Mux"},
1387 {"SDI2 TX Mux", "IF2", "DAI2 IF2 Mux"},
1389 {"AIF1TX", NULL
, "DAI1 TX Mux"},
1390 {"AIF1TX", NULL
, "SDI1 TX Mux"},
1391 {"AIF2TX", NULL
, "DAI2 TX Mux"},
1392 {"AIF2TX", NULL
, "SDI2 TX Mux"},
1394 {"DAI1 RX Mux", "1:1|2:2", "AIF1RX"},
1395 {"DAI1 RX Mux", "1:1|2:1", "AIF1RX"},
1396 {"DAI1 RX Mux", "1:2|2:1", "AIF2RX"},
1397 {"DAI1 RX Mux", "1:2|2:2", "AIF2RX"},
1399 {"DAI2 RX Mux", "1:2|2:1", "AIF1RX"},
1400 {"DAI2 RX Mux", "1:1|2:1", "AIF1RX"},
1401 {"DAI2 RX Mux", "1:1|2:2", "AIF2RX"},
1402 {"DAI2 RX Mux", "1:2|2:2", "AIF2RX"},
1404 {"IF1 DAC", NULL
, "I2S1"},
1405 {"IF1 DAC", NULL
, "DAI1 RX Mux"},
1406 {"IF2 DAC", NULL
, "I2S2"},
1407 {"IF2 DAC", NULL
, "DAI2 RX Mux"},
1409 {"IF1 DAC L", NULL
, "IF1 DAC"},
1410 {"IF1 DAC R", NULL
, "IF1 DAC"},
1411 {"IF2 DAC L", NULL
, "IF2 DAC"},
1412 {"IF2 DAC R", NULL
, "IF2 DAC"},
1414 {"DAC MIXL", "Stereo ADC Switch", "Stereo ADC MIXL"},
1415 {"DAC MIXL", "INF1 Switch", "IF1 DAC L"},
1416 {"DAC MIXR", "Stereo ADC Switch", "Stereo ADC MIXR"},
1417 {"DAC MIXR", "INF1 Switch", "IF1 DAC R"},
1419 {"Stereo DAC MIXL", "DAC L1 Switch", "DAC MIXL"},
1420 {"Stereo DAC MIXR", "DAC R1 Switch", "DAC MIXR"},
1422 {"Mono DAC MIXL", "DAC L1 Switch", "DAC MIXL"},
1423 {"Mono DAC MIXR", "DAC R1 Switch", "DAC MIXR"},
1425 {"DIG MIXL", "DAC L1 Switch", "DAC MIXL"},
1426 {"DIG MIXR", "DAC R1 Switch", "DAC MIXR"},
1428 {"DAC L1", NULL
, "Stereo DAC MIXL"},
1429 {"DAC L1", NULL
, "PLL1", is_sys_clk_from_pll
},
1430 {"DAC R1", NULL
, "Stereo DAC MIXR"},
1431 {"DAC R1", NULL
, "PLL1", is_sys_clk_from_pll
},
1433 {"SPK MIXL", "REC MIXL Switch", "RECMIXL"},
1434 {"SPK MIXL", "INL Switch", "INL VOL"},
1435 {"SPK MIXL", "DAC L1 Switch", "DAC L1"},
1436 {"SPK MIXL", "OUT MIXL Switch", "OUT MIXL"},
1437 {"SPK MIXR", "REC MIXR Switch", "RECMIXR"},
1438 {"SPK MIXR", "INR Switch", "INR VOL"},
1439 {"SPK MIXR", "DAC R1 Switch", "DAC R1"},
1440 {"SPK MIXR", "OUT MIXR Switch", "OUT MIXR"},
1442 {"OUT MIXL", "BST1 Switch", "BST1"},
1443 {"OUT MIXL", "INL Switch", "INL VOL"},
1444 {"OUT MIXL", "REC MIXL Switch", "RECMIXL"},
1445 {"OUT MIXL", "DAC L1 Switch", "DAC L1"},
1447 {"OUT MIXR", "BST2 Switch", "BST2"},
1448 {"OUT MIXR", "BST1 Switch", "BST1"},
1449 {"OUT MIXR", "INR Switch", "INR VOL"},
1450 {"OUT MIXR", "REC MIXR Switch", "RECMIXR"},
1451 {"OUT MIXR", "DAC R1 Switch", "DAC R1"},
1453 {"SPKVOL L", NULL
, "SPK MIXL"},
1454 {"SPKVOL R", NULL
, "SPK MIXR"},
1455 {"HPOVOL L", NULL
, "OUT MIXL"},
1456 {"HPOVOL R", NULL
, "OUT MIXR"},
1457 {"OUTVOL L", NULL
, "OUT MIXL"},
1458 {"OUTVOL R", NULL
, "OUT MIXR"},
1460 {"SPOL MIX", "DAC R1 Switch", "DAC R1"},
1461 {"SPOL MIX", "DAC L1 Switch", "DAC L1"},
1462 {"SPOL MIX", "SPKVOL R Switch", "SPKVOL R"},
1463 {"SPOL MIX", "SPKVOL L Switch", "SPKVOL L"},
1464 {"SPOL MIX", "BST1 Switch", "BST1"},
1465 {"SPOR MIX", "DAC R1 Switch", "DAC R1"},
1466 {"SPOR MIX", "SPKVOL R Switch", "SPKVOL R"},
1467 {"SPOR MIX", "BST1 Switch", "BST1"},
1469 {"HPO MIX L", "HPO MIX DAC1 Switch", "DAC L1"},
1470 {"HPO MIX L", "HPO MIX HPVOL Switch", "HPOVOL L"},
1471 {"HPO MIX L", NULL
, "HP L Amp"},
1472 {"HPO MIX R", "HPO MIX DAC1 Switch", "DAC R1"},
1473 {"HPO MIX R", "HPO MIX HPVOL Switch", "HPOVOL R"},
1474 {"HPO MIX R", NULL
, "HP R Amp"},
1476 {"LOUT MIX", "DAC L1 Switch", "DAC L1"},
1477 {"LOUT MIX", "DAC R1 Switch", "DAC R1"},
1478 {"LOUT MIX", "OUTVOL L Switch", "OUTVOL L"},
1479 {"LOUT MIX", "OUTVOL R Switch", "OUTVOL R"},
1481 {"HP Amp", NULL
, "HPO MIX L"},
1482 {"HP Amp", NULL
, "HPO MIX R"},
1484 {"Speaker L Playback", "Switch", "SPOL MIX"},
1485 {"Speaker R Playback", "Switch", "SPOR MIX"},
1486 {"SPOLP", NULL
, "Speaker L Playback"},
1487 {"SPOLN", NULL
, "Speaker L Playback"},
1488 {"SPORP", NULL
, "Speaker R Playback"},
1489 {"SPORN", NULL
, "Speaker R Playback"},
1491 {"SPOLP", NULL
, "Improve SPK Amp Drv"},
1492 {"SPOLN", NULL
, "Improve SPK Amp Drv"},
1493 {"SPORP", NULL
, "Improve SPK Amp Drv"},
1494 {"SPORN", NULL
, "Improve SPK Amp Drv"},
1496 {"HPOL", NULL
, "Improve HP Amp Drv"},
1497 {"HPOR", NULL
, "Improve HP Amp Drv"},
1499 {"HP L Playback", "Switch", "HP Amp"},
1500 {"HP R Playback", "Switch", "HP Amp"},
1501 {"HPOL", NULL
, "HP L Playback"},
1502 {"HPOR", NULL
, "HP R Playback"},
1503 {"LOUTL", NULL
, "LOUT MIX"},
1504 {"LOUTR", NULL
, "LOUT MIX"},
1507 static const struct snd_soc_dapm_route rt5640_specific_dapm_routes
[] = {
1508 {"ANC", NULL
, "Stereo ADC MIXL"},
1509 {"ANC", NULL
, "Stereo ADC MIXR"},
1511 {"Audio DSP", NULL
, "DAC MIXL"},
1512 {"Audio DSP", NULL
, "DAC MIXR"},
1514 {"DAC L2 Mux", "IF2", "IF2 DAC L"},
1515 {"DAC L2 Mux", "Base L/R", "Audio DSP"},
1517 {"DAC R2 Mux", "IF2", "IF2 DAC R"},
1519 {"Stereo DAC MIXL", "DAC L2 Switch", "DAC L2 Mux"},
1520 {"Stereo DAC MIXL", "ANC Switch", "ANC"},
1521 {"Stereo DAC MIXR", "DAC R2 Switch", "DAC R2 Mux"},
1522 {"Stereo DAC MIXR", "ANC Switch", "ANC"},
1524 {"Mono DAC MIXL", "DAC L2 Switch", "DAC L2 Mux"},
1525 {"Mono DAC MIXL", "DAC R2 Switch", "DAC R2 Mux"},
1527 {"Mono DAC MIXR", "DAC R2 Switch", "DAC R2 Mux"},
1528 {"Mono DAC MIXR", "DAC L2 Switch", "DAC L2 Mux"},
1530 {"DIG MIXR", "DAC R2 Switch", "DAC R2 Mux"},
1531 {"DIG MIXL", "DAC L2 Switch", "DAC L2 Mux"},
1533 {"DAC L2", NULL
, "Mono DAC MIXL"},
1534 {"DAC L2", NULL
, "PLL1", is_sys_clk_from_pll
},
1535 {"DAC R2", NULL
, "Mono DAC MIXR"},
1536 {"DAC R2", NULL
, "PLL1", is_sys_clk_from_pll
},
1538 {"SPK MIXL", "DAC L2 Switch", "DAC L2"},
1539 {"SPK MIXR", "DAC R2 Switch", "DAC R2"},
1541 {"OUT MIXL", "SPK MIXL Switch", "SPK MIXL"},
1542 {"OUT MIXR", "SPK MIXR Switch", "SPK MIXR"},
1544 {"OUT MIXL", "DAC R2 Switch", "DAC R2"},
1545 {"OUT MIXL", "DAC L2 Switch", "DAC L2"},
1547 {"OUT MIXR", "DAC L2 Switch", "DAC L2"},
1548 {"OUT MIXR", "DAC R2 Switch", "DAC R2"},
1550 {"HPO MIX L", "HPO MIX DAC2 Switch", "DAC L2"},
1551 {"HPO MIX R", "HPO MIX DAC2 Switch", "DAC R2"},
1553 {"Mono MIX", "DAC R2 Switch", "DAC R2"},
1554 {"Mono MIX", "DAC L2 Switch", "DAC L2"},
1555 {"Mono MIX", "OUTVOL R Switch", "OUTVOL R"},
1556 {"Mono MIX", "OUTVOL L Switch", "OUTVOL L"},
1557 {"Mono MIX", "BST1 Switch", "BST1"},
1559 {"MONOP", NULL
, "Mono MIX"},
1560 {"MONON", NULL
, "Mono MIX"},
1561 {"MONOP", NULL
, "Improve MONO Amp Drv"},
1564 static const struct snd_soc_dapm_route rt5639_specific_dapm_routes
[] = {
1565 {"Stereo DAC MIXL", "DAC L2 Switch", "IF2 DAC L"},
1566 {"Stereo DAC MIXR", "DAC R2 Switch", "IF2 DAC R"},
1568 {"Mono DAC MIXL", "DAC L2 Switch", "IF2 DAC L"},
1569 {"Mono DAC MIXL", "DAC R2 Switch", "IF2 DAC R"},
1571 {"Mono DAC MIXR", "DAC R2 Switch", "IF2 DAC R"},
1572 {"Mono DAC MIXR", "DAC L2 Switch", "IF2 DAC L"},
1574 {"DIG MIXL", "DAC L2 Switch", "IF2 DAC L"},
1575 {"DIG MIXR", "DAC R2 Switch", "IF2 DAC R"},
1577 {"IF2 DAC L", NULL
, "DAC L2 Filter"},
1578 {"IF2 DAC R", NULL
, "DAC R2 Filter"},
1581 static int get_sdp_info(struct snd_soc_codec
*codec
, int dai_id
)
1588 val
= snd_soc_read(codec
, RT5640_I2S1_SDP
);
1589 val
= (val
& RT5640_I2S_IF_MASK
) >> RT5640_I2S_IF_SFT
;
1595 ret
|= RT5640_U_IF1
;
1598 ret
|= RT5640_U_IF1
;
1601 ret
|= RT5640_U_IF2
;
1610 ret
|= RT5640_U_IF1
;
1613 ret
|= RT5640_U_IF1
;
1616 ret
|= RT5640_U_IF2
;
1629 static int rt5640_hw_params(struct snd_pcm_substream
*substream
,
1630 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
1632 struct snd_soc_codec
*codec
= dai
->codec
;
1633 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1634 unsigned int val_len
= 0, val_clk
, mask_clk
;
1635 int dai_sel
, pre_div
, bclk_ms
, frame_size
;
1637 rt5640
->lrck
[dai
->id
] = params_rate(params
);
1638 pre_div
= rl6231_get_clk_info(rt5640
->sysclk
, rt5640
->lrck
[dai
->id
]);
1640 dev_err(codec
->dev
, "Unsupported clock setting %d for DAI %d\n",
1641 rt5640
->lrck
[dai
->id
], dai
->id
);
1644 frame_size
= snd_soc_params_to_frame_size(params
);
1645 if (frame_size
< 0) {
1646 dev_err(codec
->dev
, "Unsupported frame size: %d\n", frame_size
);
1649 if (frame_size
> 32)
1653 rt5640
->bclk
[dai
->id
] = rt5640
->lrck
[dai
->id
] * (32 << bclk_ms
);
1655 dev_dbg(dai
->dev
, "bclk is %dHz and lrck is %dHz\n",
1656 rt5640
->bclk
[dai
->id
], rt5640
->lrck
[dai
->id
]);
1657 dev_dbg(dai
->dev
, "bclk_ms is %d and pre_div is %d for iis %d\n",
1658 bclk_ms
, pre_div
, dai
->id
);
1660 switch (params_width(params
)) {
1664 val_len
|= RT5640_I2S_DL_20
;
1667 val_len
|= RT5640_I2S_DL_24
;
1670 val_len
|= RT5640_I2S_DL_8
;
1676 dai_sel
= get_sdp_info(codec
, dai
->id
);
1678 dev_err(codec
->dev
, "Failed to get sdp info: %d\n", dai_sel
);
1681 if (dai_sel
& RT5640_U_IF1
) {
1682 mask_clk
= RT5640_I2S_BCLK_MS1_MASK
| RT5640_I2S_PD1_MASK
;
1683 val_clk
= bclk_ms
<< RT5640_I2S_BCLK_MS1_SFT
|
1684 pre_div
<< RT5640_I2S_PD1_SFT
;
1685 snd_soc_update_bits(codec
, RT5640_I2S1_SDP
,
1686 RT5640_I2S_DL_MASK
, val_len
);
1687 snd_soc_update_bits(codec
, RT5640_ADDA_CLK1
, mask_clk
, val_clk
);
1689 if (dai_sel
& RT5640_U_IF2
) {
1690 mask_clk
= RT5640_I2S_BCLK_MS2_MASK
| RT5640_I2S_PD2_MASK
;
1691 val_clk
= bclk_ms
<< RT5640_I2S_BCLK_MS2_SFT
|
1692 pre_div
<< RT5640_I2S_PD2_SFT
;
1693 snd_soc_update_bits(codec
, RT5640_I2S2_SDP
,
1694 RT5640_I2S_DL_MASK
, val_len
);
1695 snd_soc_update_bits(codec
, RT5640_ADDA_CLK1
, mask_clk
, val_clk
);
1701 static int rt5640_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
1703 struct snd_soc_codec
*codec
= dai
->codec
;
1704 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1705 unsigned int reg_val
= 0;
1708 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1709 case SND_SOC_DAIFMT_CBM_CFM
:
1710 rt5640
->master
[dai
->id
] = 1;
1712 case SND_SOC_DAIFMT_CBS_CFS
:
1713 reg_val
|= RT5640_I2S_MS_S
;
1714 rt5640
->master
[dai
->id
] = 0;
1720 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1721 case SND_SOC_DAIFMT_NB_NF
:
1723 case SND_SOC_DAIFMT_IB_NF
:
1724 reg_val
|= RT5640_I2S_BP_INV
;
1730 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1731 case SND_SOC_DAIFMT_I2S
:
1733 case SND_SOC_DAIFMT_LEFT_J
:
1734 reg_val
|= RT5640_I2S_DF_LEFT
;
1736 case SND_SOC_DAIFMT_DSP_A
:
1737 reg_val
|= RT5640_I2S_DF_PCM_A
;
1739 case SND_SOC_DAIFMT_DSP_B
:
1740 reg_val
|= RT5640_I2S_DF_PCM_B
;
1746 dai_sel
= get_sdp_info(codec
, dai
->id
);
1748 dev_err(codec
->dev
, "Failed to get sdp info: %d\n", dai_sel
);
1751 if (dai_sel
& RT5640_U_IF1
) {
1752 snd_soc_update_bits(codec
, RT5640_I2S1_SDP
,
1753 RT5640_I2S_MS_MASK
| RT5640_I2S_BP_MASK
|
1754 RT5640_I2S_DF_MASK
, reg_val
);
1756 if (dai_sel
& RT5640_U_IF2
) {
1757 snd_soc_update_bits(codec
, RT5640_I2S2_SDP
,
1758 RT5640_I2S_MS_MASK
| RT5640_I2S_BP_MASK
|
1759 RT5640_I2S_DF_MASK
, reg_val
);
1765 static int rt5640_set_dai_sysclk(struct snd_soc_dai
*dai
,
1766 int clk_id
, unsigned int freq
, int dir
)
1768 struct snd_soc_codec
*codec
= dai
->codec
;
1769 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1770 unsigned int reg_val
= 0;
1772 if (freq
== rt5640
->sysclk
&& clk_id
== rt5640
->sysclk_src
)
1776 case RT5640_SCLK_S_MCLK
:
1777 reg_val
|= RT5640_SCLK_SRC_MCLK
;
1779 case RT5640_SCLK_S_PLL1
:
1780 reg_val
|= RT5640_SCLK_SRC_PLL1
;
1783 dev_err(codec
->dev
, "Invalid clock id (%d)\n", clk_id
);
1786 snd_soc_update_bits(codec
, RT5640_GLB_CLK
,
1787 RT5640_SCLK_SRC_MASK
, reg_val
);
1788 rt5640
->sysclk
= freq
;
1789 rt5640
->sysclk_src
= clk_id
;
1791 dev_dbg(dai
->dev
, "Sysclk is %dHz and clock id is %d\n", freq
, clk_id
);
1795 static int rt5640_set_dai_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
1796 unsigned int freq_in
, unsigned int freq_out
)
1798 struct snd_soc_codec
*codec
= dai
->codec
;
1799 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1800 struct rl6231_pll_code pll_code
;
1803 if (source
== rt5640
->pll_src
&& freq_in
== rt5640
->pll_in
&&
1804 freq_out
== rt5640
->pll_out
)
1807 if (!freq_in
|| !freq_out
) {
1808 dev_dbg(codec
->dev
, "PLL disabled\n");
1811 rt5640
->pll_out
= 0;
1812 snd_soc_update_bits(codec
, RT5640_GLB_CLK
,
1813 RT5640_SCLK_SRC_MASK
, RT5640_SCLK_SRC_MCLK
);
1818 case RT5640_PLL1_S_MCLK
:
1819 snd_soc_update_bits(codec
, RT5640_GLB_CLK
,
1820 RT5640_PLL1_SRC_MASK
, RT5640_PLL1_SRC_MCLK
);
1822 case RT5640_PLL1_S_BCLK1
:
1823 case RT5640_PLL1_S_BCLK2
:
1824 dai_sel
= get_sdp_info(codec
, dai
->id
);
1827 "Failed to get sdp info: %d\n", dai_sel
);
1830 if (dai_sel
& RT5640_U_IF1
) {
1831 snd_soc_update_bits(codec
, RT5640_GLB_CLK
,
1832 RT5640_PLL1_SRC_MASK
, RT5640_PLL1_SRC_BCLK1
);
1834 if (dai_sel
& RT5640_U_IF2
) {
1835 snd_soc_update_bits(codec
, RT5640_GLB_CLK
,
1836 RT5640_PLL1_SRC_MASK
, RT5640_PLL1_SRC_BCLK2
);
1840 dev_err(codec
->dev
, "Unknown PLL source %d\n", source
);
1844 ret
= rl6231_pll_calc(freq_in
, freq_out
, &pll_code
);
1846 dev_err(codec
->dev
, "Unsupport input clock %d\n", freq_in
);
1850 dev_dbg(codec
->dev
, "bypass=%d m=%d n=%d k=%d\n",
1851 pll_code
.m_bp
, (pll_code
.m_bp
? 0 : pll_code
.m_code
),
1852 pll_code
.n_code
, pll_code
.k_code
);
1854 snd_soc_write(codec
, RT5640_PLL_CTRL1
,
1855 pll_code
.n_code
<< RT5640_PLL_N_SFT
| pll_code
.k_code
);
1856 snd_soc_write(codec
, RT5640_PLL_CTRL2
,
1857 (pll_code
.m_bp
? 0 : pll_code
.m_code
) << RT5640_PLL_M_SFT
|
1858 pll_code
.m_bp
<< RT5640_PLL_M_BP_SFT
);
1860 rt5640
->pll_in
= freq_in
;
1861 rt5640
->pll_out
= freq_out
;
1862 rt5640
->pll_src
= source
;
1867 static int rt5640_set_bias_level(struct snd_soc_codec
*codec
,
1868 enum snd_soc_bias_level level
)
1871 case SND_SOC_BIAS_STANDBY
:
1872 if (SND_SOC_BIAS_OFF
== snd_soc_codec_get_bias_level(codec
)) {
1873 snd_soc_update_bits(codec
, RT5640_PWR_ANLG1
,
1874 RT5640_PWR_VREF1
| RT5640_PWR_MB
|
1875 RT5640_PWR_BG
| RT5640_PWR_VREF2
,
1876 RT5640_PWR_VREF1
| RT5640_PWR_MB
|
1877 RT5640_PWR_BG
| RT5640_PWR_VREF2
);
1878 usleep_range(10000, 15000);
1879 snd_soc_update_bits(codec
, RT5640_PWR_ANLG1
,
1880 RT5640_PWR_FV1
| RT5640_PWR_FV2
,
1881 RT5640_PWR_FV1
| RT5640_PWR_FV2
);
1882 snd_soc_update_bits(codec
, RT5640_DUMMY1
,
1884 snd_soc_update_bits(codec
, RT5640_MICBIAS
,
1889 case SND_SOC_BIAS_OFF
:
1890 snd_soc_write(codec
, RT5640_DEPOP_M1
, 0x0004);
1891 snd_soc_write(codec
, RT5640_DEPOP_M2
, 0x1100);
1892 snd_soc_update_bits(codec
, RT5640_DUMMY1
, 0x1, 0);
1893 snd_soc_write(codec
, RT5640_PWR_DIG1
, 0x0000);
1894 snd_soc_write(codec
, RT5640_PWR_DIG2
, 0x0000);
1895 snd_soc_write(codec
, RT5640_PWR_VOL
, 0x0000);
1896 snd_soc_write(codec
, RT5640_PWR_MIXER
, 0x0000);
1897 snd_soc_write(codec
, RT5640_PWR_ANLG1
, 0x0000);
1898 snd_soc_write(codec
, RT5640_PWR_ANLG2
, 0x0000);
1908 int rt5640_dmic_enable(struct snd_soc_codec
*codec
,
1909 bool dmic1_data_pin
, bool dmic2_data_pin
)
1911 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1913 regmap_update_bits(rt5640
->regmap
, RT5640_GPIO_CTRL1
,
1914 RT5640_GP2_PIN_MASK
, RT5640_GP2_PIN_DMIC1_SCL
);
1916 if (dmic1_data_pin
) {
1917 regmap_update_bits(rt5640
->regmap
, RT5640_DMIC
,
1918 RT5640_DMIC_1_DP_MASK
, RT5640_DMIC_1_DP_GPIO3
);
1919 regmap_update_bits(rt5640
->regmap
, RT5640_GPIO_CTRL1
,
1920 RT5640_GP3_PIN_MASK
, RT5640_GP3_PIN_DMIC1_SDA
);
1923 if (dmic2_data_pin
) {
1924 regmap_update_bits(rt5640
->regmap
, RT5640_DMIC
,
1925 RT5640_DMIC_2_DP_MASK
, RT5640_DMIC_2_DP_GPIO4
);
1926 regmap_update_bits(rt5640
->regmap
, RT5640_GPIO_CTRL1
,
1927 RT5640_GP4_PIN_MASK
, RT5640_GP4_PIN_DMIC2_SDA
);
1932 EXPORT_SYMBOL_GPL(rt5640_dmic_enable
);
1934 static int rt5640_probe(struct snd_soc_codec
*codec
)
1936 struct snd_soc_dapm_context
*dapm
= snd_soc_codec_get_dapm(codec
);
1937 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1939 rt5640
->codec
= codec
;
1941 snd_soc_codec_force_bias_level(codec
, SND_SOC_BIAS_OFF
);
1943 snd_soc_update_bits(codec
, RT5640_DUMMY1
, 0x0301, 0x0301);
1944 snd_soc_update_bits(codec
, RT5640_MICBIAS
, 0x0030, 0x0030);
1945 snd_soc_update_bits(codec
, RT5640_DSP_PATH2
, 0xfc00, 0x0c00);
1947 switch (snd_soc_read(codec
, RT5640_RESET
) & RT5640_ID_MASK
) {
1948 case RT5640_ID_5640
:
1949 case RT5640_ID_5642
:
1950 snd_soc_add_codec_controls(codec
,
1951 rt5640_specific_snd_controls
,
1952 ARRAY_SIZE(rt5640_specific_snd_controls
));
1953 snd_soc_dapm_new_controls(dapm
,
1954 rt5640_specific_dapm_widgets
,
1955 ARRAY_SIZE(rt5640_specific_dapm_widgets
));
1956 snd_soc_dapm_add_routes(dapm
,
1957 rt5640_specific_dapm_routes
,
1958 ARRAY_SIZE(rt5640_specific_dapm_routes
));
1960 case RT5640_ID_5639
:
1961 snd_soc_dapm_new_controls(dapm
,
1962 rt5639_specific_dapm_widgets
,
1963 ARRAY_SIZE(rt5639_specific_dapm_widgets
));
1964 snd_soc_dapm_add_routes(dapm
,
1965 rt5639_specific_dapm_routes
,
1966 ARRAY_SIZE(rt5639_specific_dapm_routes
));
1970 "The driver is for RT5639 RT5640 or RT5642 only\n");
1974 if (rt5640
->pdata
.dmic_en
)
1975 rt5640_dmic_enable(codec
, rt5640
->pdata
.dmic1_data_pin
,
1976 rt5640
->pdata
.dmic2_data_pin
);
1981 static int rt5640_remove(struct snd_soc_codec
*codec
)
1983 rt5640_reset(codec
);
1989 static int rt5640_suspend(struct snd_soc_codec
*codec
)
1991 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1993 snd_soc_codec_force_bias_level(codec
, SND_SOC_BIAS_OFF
);
1994 rt5640_reset(codec
);
1995 regcache_cache_only(rt5640
->regmap
, true);
1996 regcache_mark_dirty(rt5640
->regmap
);
1997 if (gpio_is_valid(rt5640
->pdata
.ldo1_en
))
1998 gpio_set_value_cansleep(rt5640
->pdata
.ldo1_en
, 0);
2003 static int rt5640_resume(struct snd_soc_codec
*codec
)
2005 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
2007 if (gpio_is_valid(rt5640
->pdata
.ldo1_en
)) {
2008 gpio_set_value_cansleep(rt5640
->pdata
.ldo1_en
, 1);
2012 regcache_cache_only(rt5640
->regmap
, false);
2013 regcache_sync(rt5640
->regmap
);
2018 #define rt5640_suspend NULL
2019 #define rt5640_resume NULL
2022 #define RT5640_STEREO_RATES SNDRV_PCM_RATE_8000_96000
2023 #define RT5640_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
2024 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
2026 static const struct snd_soc_dai_ops rt5640_aif_dai_ops
= {
2027 .hw_params
= rt5640_hw_params
,
2028 .set_fmt
= rt5640_set_dai_fmt
,
2029 .set_sysclk
= rt5640_set_dai_sysclk
,
2030 .set_pll
= rt5640_set_dai_pll
,
2033 static struct snd_soc_dai_driver rt5640_dai
[] = {
2035 .name
= "rt5640-aif1",
2038 .stream_name
= "AIF1 Playback",
2041 .rates
= RT5640_STEREO_RATES
,
2042 .formats
= RT5640_FORMATS
,
2045 .stream_name
= "AIF1 Capture",
2048 .rates
= RT5640_STEREO_RATES
,
2049 .formats
= RT5640_FORMATS
,
2051 .ops
= &rt5640_aif_dai_ops
,
2054 .name
= "rt5640-aif2",
2057 .stream_name
= "AIF2 Playback",
2060 .rates
= RT5640_STEREO_RATES
,
2061 .formats
= RT5640_FORMATS
,
2064 .stream_name
= "AIF2 Capture",
2067 .rates
= RT5640_STEREO_RATES
,
2068 .formats
= RT5640_FORMATS
,
2070 .ops
= &rt5640_aif_dai_ops
,
2074 static struct snd_soc_codec_driver soc_codec_dev_rt5640
= {
2075 .probe
= rt5640_probe
,
2076 .remove
= rt5640_remove
,
2077 .suspend
= rt5640_suspend
,
2078 .resume
= rt5640_resume
,
2079 .set_bias_level
= rt5640_set_bias_level
,
2080 .idle_bias_off
= true,
2081 .controls
= rt5640_snd_controls
,
2082 .num_controls
= ARRAY_SIZE(rt5640_snd_controls
),
2083 .dapm_widgets
= rt5640_dapm_widgets
,
2084 .num_dapm_widgets
= ARRAY_SIZE(rt5640_dapm_widgets
),
2085 .dapm_routes
= rt5640_dapm_routes
,
2086 .num_dapm_routes
= ARRAY_SIZE(rt5640_dapm_routes
),
2089 static const struct regmap_config rt5640_regmap
= {
2092 .use_single_rw
= true,
2094 .max_register
= RT5640_VENDOR_ID2
+ 1 + (ARRAY_SIZE(rt5640_ranges
) *
2096 .volatile_reg
= rt5640_volatile_register
,
2097 .readable_reg
= rt5640_readable_register
,
2099 .cache_type
= REGCACHE_RBTREE
,
2100 .reg_defaults
= rt5640_reg
,
2101 .num_reg_defaults
= ARRAY_SIZE(rt5640_reg
),
2102 .ranges
= rt5640_ranges
,
2103 .num_ranges
= ARRAY_SIZE(rt5640_ranges
),
2106 static const struct i2c_device_id rt5640_i2c_id
[] = {
2112 MODULE_DEVICE_TABLE(i2c
, rt5640_i2c_id
);
2114 #if defined(CONFIG_OF)
2115 static const struct of_device_id rt5640_of_match
[] = {
2116 { .compatible
= "realtek,rt5639", },
2117 { .compatible
= "realtek,rt5640", },
2120 MODULE_DEVICE_TABLE(of
, rt5640_of_match
);
2124 static const struct acpi_device_id rt5640_acpi_match
[] = {
2130 MODULE_DEVICE_TABLE(acpi
, rt5640_acpi_match
);
2133 static int rt5640_parse_dt(struct rt5640_priv
*rt5640
, struct device_node
*np
)
2135 rt5640
->pdata
.in1_diff
= of_property_read_bool(np
,
2136 "realtek,in1-differential");
2137 rt5640
->pdata
.in2_diff
= of_property_read_bool(np
,
2138 "realtek,in2-differential");
2140 rt5640
->pdata
.ldo1_en
= of_get_named_gpio(np
,
2141 "realtek,ldo1-en-gpios", 0);
2143 * LDO1_EN is optional (it may be statically tied on the board).
2144 * -ENOENT means that the property doesn't exist, i.e. there is no
2145 * GPIO, so is not an error. Any other error code means the property
2146 * exists, but could not be parsed.
2148 if (!gpio_is_valid(rt5640
->pdata
.ldo1_en
) &&
2149 (rt5640
->pdata
.ldo1_en
!= -ENOENT
))
2150 return rt5640
->pdata
.ldo1_en
;
2155 static int rt5640_i2c_probe(struct i2c_client
*i2c
,
2156 const struct i2c_device_id
*id
)
2158 struct rt5640_platform_data
*pdata
= dev_get_platdata(&i2c
->dev
);
2159 struct rt5640_priv
*rt5640
;
2163 rt5640
= devm_kzalloc(&i2c
->dev
,
2164 sizeof(struct rt5640_priv
),
2168 i2c_set_clientdata(i2c
, rt5640
);
2171 rt5640
->pdata
= *pdata
;
2173 * Translate zero'd out (default) pdata value to an invalid
2174 * GPIO ID. This makes the pdata and DT paths consistent in
2175 * terms of the value left in this field when no GPIO is
2176 * specified, but means we can't actually use GPIO 0.
2178 if (!rt5640
->pdata
.ldo1_en
)
2179 rt5640
->pdata
.ldo1_en
= -EINVAL
;
2180 } else if (i2c
->dev
.of_node
) {
2181 ret
= rt5640_parse_dt(rt5640
, i2c
->dev
.of_node
);
2185 rt5640
->pdata
.ldo1_en
= -EINVAL
;
2187 rt5640
->regmap
= devm_regmap_init_i2c(i2c
, &rt5640_regmap
);
2188 if (IS_ERR(rt5640
->regmap
)) {
2189 ret
= PTR_ERR(rt5640
->regmap
);
2190 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
2195 if (gpio_is_valid(rt5640
->pdata
.ldo1_en
)) {
2196 ret
= devm_gpio_request_one(&i2c
->dev
, rt5640
->pdata
.ldo1_en
,
2197 GPIOF_OUT_INIT_HIGH
,
2200 dev_err(&i2c
->dev
, "Failed to request LDO1_EN %d: %d\n",
2201 rt5640
->pdata
.ldo1_en
, ret
);
2207 regmap_read(rt5640
->regmap
, RT5640_VENDOR_ID2
, &val
);
2208 if (val
!= RT5640_DEVICE_ID
) {
2210 "Device with ID register %x is not rt5640/39\n", val
);
2214 regmap_write(rt5640
->regmap
, RT5640_RESET
, 0);
2216 ret
= regmap_register_patch(rt5640
->regmap
, init_list
,
2217 ARRAY_SIZE(init_list
));
2219 dev_warn(&i2c
->dev
, "Failed to apply regmap patch: %d\n", ret
);
2221 if (rt5640
->pdata
.in1_diff
)
2222 regmap_update_bits(rt5640
->regmap
, RT5640_IN1_IN2
,
2223 RT5640_IN_DF1
, RT5640_IN_DF1
);
2225 if (rt5640
->pdata
.in2_diff
)
2226 regmap_update_bits(rt5640
->regmap
, RT5640_IN3_IN4
,
2227 RT5640_IN_DF2
, RT5640_IN_DF2
);
2229 rt5640
->hp_mute
= 1;
2231 return snd_soc_register_codec(&i2c
->dev
, &soc_codec_dev_rt5640
,
2232 rt5640_dai
, ARRAY_SIZE(rt5640_dai
));
2235 static int rt5640_i2c_remove(struct i2c_client
*i2c
)
2237 snd_soc_unregister_codec(&i2c
->dev
);
2242 static struct i2c_driver rt5640_i2c_driver
= {
2245 .owner
= THIS_MODULE
,
2246 .acpi_match_table
= ACPI_PTR(rt5640_acpi_match
),
2247 .of_match_table
= of_match_ptr(rt5640_of_match
),
2249 .probe
= rt5640_i2c_probe
,
2250 .remove
= rt5640_i2c_remove
,
2251 .id_table
= rt5640_i2c_id
,
2253 module_i2c_driver(rt5640_i2c_driver
);
2255 MODULE_DESCRIPTION("ASoC RT5640/RT5639 driver");
2256 MODULE_AUTHOR("Johnny Hsu <johnnyhsu@realtek.com>");
2257 MODULE_LICENSE("GPL v2");