2 * rt5645.c -- RT5645 ALSA SoC audio codec driver
4 * Copyright 2013 Realtek Semiconductor Corp.
5 * Author: Bard Liao <bardliao@realtek.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/init.h>
15 #include <linux/delay.h>
17 #include <linux/i2c.h>
18 #include <linux/platform_device.h>
19 #include <linux/spi/spi.h>
20 #include <linux/gpio.h>
21 #include <linux/acpi.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/jack.h>
26 #include <sound/soc.h>
27 #include <sound/soc-dapm.h>
28 #include <sound/initval.h>
29 #include <sound/tlv.h>
34 #define RT5645_DEVICE_ID 0x6308
35 #define RT5650_DEVICE_ID 0x6419
37 #define RT5645_PR_RANGE_BASE (0xff + 1)
38 #define RT5645_PR_SPACING 0x100
40 #define RT5645_PR_BASE (RT5645_PR_RANGE_BASE + (0 * RT5645_PR_SPACING))
42 static const struct regmap_range_cfg rt5645_ranges
[] = {
45 .range_min
= RT5645_PR_BASE
,
46 .range_max
= RT5645_PR_BASE
+ 0xf8,
47 .selector_reg
= RT5645_PRIV_INDEX
,
48 .selector_mask
= 0xff,
49 .selector_shift
= 0x0,
50 .window_start
= RT5645_PRIV_DATA
,
55 static const struct reg_default init_list
[] = {
56 {RT5645_PR_BASE
+ 0x3d, 0x3600},
57 {RT5645_PR_BASE
+ 0x1c, 0xfd20},
58 {RT5645_PR_BASE
+ 0x20, 0x611f},
59 {RT5645_PR_BASE
+ 0x21, 0x4040},
60 {RT5645_PR_BASE
+ 0x23, 0x0004},
62 #define RT5645_INIT_REG_LEN ARRAY_SIZE(init_list)
64 static const struct reg_default rt5650_init_list
[] = {
68 static const struct reg_default rt5645_reg
[] = {
224 static int rt5645_reset(struct snd_soc_codec
*codec
)
226 return snd_soc_write(codec
, RT5645_RESET
, 0);
229 static bool rt5645_volatile_register(struct device
*dev
, unsigned int reg
)
233 for (i
= 0; i
< ARRAY_SIZE(rt5645_ranges
); i
++) {
234 if (reg
>= rt5645_ranges
[i
].range_min
&&
235 reg
<= rt5645_ranges
[i
].range_max
) {
242 case RT5645_PRIV_DATA
:
243 case RT5645_IN1_CTRL1
:
244 case RT5645_IN1_CTRL2
:
245 case RT5645_IN1_CTRL3
:
246 case RT5645_A_JD_CTRL1
:
247 case RT5645_ADC_EQ_CTRL1
:
248 case RT5645_EQ_CTRL1
:
249 case RT5645_ALC_CTRL_1
:
250 case RT5645_IRQ_CTRL2
:
251 case RT5645_IRQ_CTRL3
:
252 case RT5645_INT_IRQ_ST
:
254 case RT5650_4BTN_IL_CMD1
:
255 case RT5645_VENDOR_ID
:
256 case RT5645_VENDOR_ID1
:
257 case RT5645_VENDOR_ID2
:
264 static bool rt5645_readable_register(struct device
*dev
, unsigned int reg
)
268 for (i
= 0; i
< ARRAY_SIZE(rt5645_ranges
); i
++) {
269 if (reg
>= rt5645_ranges
[i
].range_min
&&
270 reg
<= rt5645_ranges
[i
].range_max
) {
280 case RT5645_IN1_CTRL1
:
281 case RT5645_IN1_CTRL2
:
282 case RT5645_IN1_CTRL3
:
283 case RT5645_IN2_CTRL
:
284 case RT5645_INL1_INR1_VOL
:
285 case RT5645_SPK_FUNC_LIM
:
286 case RT5645_ADJ_HPF_CTRL
:
287 case RT5645_DAC1_DIG_VOL
:
288 case RT5645_DAC2_DIG_VOL
:
289 case RT5645_DAC_CTRL
:
290 case RT5645_STO1_ADC_DIG_VOL
:
291 case RT5645_MONO_ADC_DIG_VOL
:
292 case RT5645_ADC_BST_VOL1
:
293 case RT5645_ADC_BST_VOL2
:
294 case RT5645_STO1_ADC_MIXER
:
295 case RT5645_MONO_ADC_MIXER
:
296 case RT5645_AD_DA_MIXER
:
297 case RT5645_STO_DAC_MIXER
:
298 case RT5645_MONO_DAC_MIXER
:
299 case RT5645_DIG_MIXER
:
300 case RT5650_A_DAC_SOUR
:
301 case RT5645_DIG_INF1_DATA
:
302 case RT5645_PDM_OUT_CTRL
:
303 case RT5645_REC_L1_MIXER
:
304 case RT5645_REC_L2_MIXER
:
305 case RT5645_REC_R1_MIXER
:
306 case RT5645_REC_R2_MIXER
:
307 case RT5645_HPMIXL_CTRL
:
308 case RT5645_HPOMIXL_CTRL
:
309 case RT5645_HPMIXR_CTRL
:
310 case RT5645_HPOMIXR_CTRL
:
311 case RT5645_HPO_MIXER
:
312 case RT5645_SPK_L_MIXER
:
313 case RT5645_SPK_R_MIXER
:
314 case RT5645_SPO_MIXER
:
315 case RT5645_SPO_CLSD_RATIO
:
316 case RT5645_OUT_L1_MIXER
:
317 case RT5645_OUT_R1_MIXER
:
318 case RT5645_OUT_L_GAIN1
:
319 case RT5645_OUT_L_GAIN2
:
320 case RT5645_OUT_R_GAIN1
:
321 case RT5645_OUT_R_GAIN2
:
322 case RT5645_LOUT_MIXER
:
323 case RT5645_HAPTIC_CTRL1
:
324 case RT5645_HAPTIC_CTRL2
:
325 case RT5645_HAPTIC_CTRL3
:
326 case RT5645_HAPTIC_CTRL4
:
327 case RT5645_HAPTIC_CTRL5
:
328 case RT5645_HAPTIC_CTRL6
:
329 case RT5645_HAPTIC_CTRL7
:
330 case RT5645_HAPTIC_CTRL8
:
331 case RT5645_HAPTIC_CTRL9
:
332 case RT5645_HAPTIC_CTRL10
:
333 case RT5645_PWR_DIG1
:
334 case RT5645_PWR_DIG2
:
335 case RT5645_PWR_ANLG1
:
336 case RT5645_PWR_ANLG2
:
337 case RT5645_PWR_MIXER
:
339 case RT5645_PRIV_INDEX
:
340 case RT5645_PRIV_DATA
:
341 case RT5645_I2S1_SDP
:
342 case RT5645_I2S2_SDP
:
343 case RT5645_ADDA_CLK1
:
344 case RT5645_ADDA_CLK2
:
345 case RT5645_DMIC_CTRL1
:
346 case RT5645_DMIC_CTRL2
:
347 case RT5645_TDM_CTRL_1
:
348 case RT5645_TDM_CTRL_2
:
349 case RT5645_TDM_CTRL_3
:
351 case RT5645_PLL_CTRL1
:
352 case RT5645_PLL_CTRL2
:
357 case RT5645_DEPOP_M1
:
358 case RT5645_DEPOP_M2
:
359 case RT5645_DEPOP_M3
:
361 case RT5645_A_JD_CTRL1
:
362 case RT5645_VAD_CTRL4
:
363 case RT5645_CLSD_OUT_CTRL
:
364 case RT5645_ADC_EQ_CTRL1
:
365 case RT5645_ADC_EQ_CTRL2
:
366 case RT5645_EQ_CTRL1
:
367 case RT5645_EQ_CTRL2
:
368 case RT5645_ALC_CTRL_1
:
369 case RT5645_ALC_CTRL_2
:
370 case RT5645_ALC_CTRL_3
:
371 case RT5645_ALC_CTRL_4
:
372 case RT5645_ALC_CTRL_5
:
374 case RT5645_IRQ_CTRL1
:
375 case RT5645_IRQ_CTRL2
:
376 case RT5645_IRQ_CTRL3
:
377 case RT5645_INT_IRQ_ST
:
378 case RT5645_GPIO_CTRL1
:
379 case RT5645_GPIO_CTRL2
:
380 case RT5645_GPIO_CTRL3
:
381 case RT5645_BASS_BACK
:
382 case RT5645_MP3_PLUS1
:
383 case RT5645_MP3_PLUS2
:
384 case RT5645_ADJ_HPF1
:
385 case RT5645_ADJ_HPF2
:
386 case RT5645_HP_CALIB_AMP_DET
:
392 case RT5650_4BTN_IL_CMD1
:
393 case RT5650_4BTN_IL_CMD2
:
394 case RT5645_DRC1_HL_CTRL1
:
395 case RT5645_DRC2_HL_CTRL1
:
396 case RT5645_ADC_MONO_HP_CTRL1
:
397 case RT5645_ADC_MONO_HP_CTRL2
:
398 case RT5645_DRC2_CTRL1
:
399 case RT5645_DRC2_CTRL2
:
400 case RT5645_DRC2_CTRL3
:
401 case RT5645_DRC2_CTRL4
:
402 case RT5645_DRC2_CTRL5
:
403 case RT5645_JD_CTRL3
:
404 case RT5645_JD_CTRL4
:
405 case RT5645_GEN_CTRL1
:
406 case RT5645_GEN_CTRL2
:
407 case RT5645_GEN_CTRL3
:
408 case RT5645_VENDOR_ID
:
409 case RT5645_VENDOR_ID1
:
410 case RT5645_VENDOR_ID2
:
417 static const DECLARE_TLV_DB_SCALE(out_vol_tlv
, -4650, 150, 0);
418 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv
, -65625, 375, 0);
419 static const DECLARE_TLV_DB_SCALE(in_vol_tlv
, -3450, 150, 0);
420 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv
, -17625, 375, 0);
421 static const DECLARE_TLV_DB_SCALE(adc_bst_tlv
, 0, 1200, 0);
423 /* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
424 static unsigned int bst_tlv
[] = {
425 TLV_DB_RANGE_HEAD(7),
426 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
427 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
428 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
429 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
430 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
431 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
432 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0),
435 static const char * const rt5645_tdm_data_swap_select
[] = {
436 "L/R", "R/L", "L/L", "R/R"
439 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot0_1_enum
,
440 RT5645_TDM_CTRL_1
, 6, rt5645_tdm_data_swap_select
);
442 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot2_3_enum
,
443 RT5645_TDM_CTRL_1
, 4, rt5645_tdm_data_swap_select
);
445 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot4_5_enum
,
446 RT5645_TDM_CTRL_1
, 2, rt5645_tdm_data_swap_select
);
448 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot6_7_enum
,
449 RT5645_TDM_CTRL_1
, 0, rt5645_tdm_data_swap_select
);
451 static const char * const rt5645_tdm_adc_data_select
[] = {
452 "1/2/R", "2/1/R", "R/1/2", "R/2/1"
455 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_sel_enum
,
456 RT5645_TDM_CTRL_1
, 8,
457 rt5645_tdm_adc_data_select
);
459 static const struct snd_kcontrol_new rt5645_snd_controls
[] = {
460 /* Speaker Output Volume */
461 SOC_DOUBLE("Speaker Channel Switch", RT5645_SPK_VOL
,
462 RT5645_VOL_L_SFT
, RT5645_VOL_R_SFT
, 1, 1),
463 SOC_DOUBLE_TLV("Speaker Playback Volume", RT5645_SPK_VOL
,
464 RT5645_L_VOL_SFT
, RT5645_R_VOL_SFT
, 39, 1, out_vol_tlv
),
466 /* Headphone Output Volume */
467 SOC_DOUBLE("HP Channel Switch", RT5645_HP_VOL
,
468 RT5645_VOL_L_SFT
, RT5645_VOL_R_SFT
, 1, 1),
469 SOC_DOUBLE_TLV("HP Playback Volume", RT5645_HP_VOL
,
470 RT5645_L_VOL_SFT
, RT5645_R_VOL_SFT
, 39, 1, out_vol_tlv
),
473 SOC_DOUBLE("OUT Playback Switch", RT5645_LOUT1
,
474 RT5645_L_MUTE_SFT
, RT5645_R_MUTE_SFT
, 1, 1),
475 SOC_DOUBLE("OUT Channel Switch", RT5645_LOUT1
,
476 RT5645_VOL_L_SFT
, RT5645_VOL_R_SFT
, 1, 1),
477 SOC_DOUBLE_TLV("OUT Playback Volume", RT5645_LOUT1
,
478 RT5645_L_VOL_SFT
, RT5645_R_VOL_SFT
, 39, 1, out_vol_tlv
),
480 /* DAC Digital Volume */
481 SOC_DOUBLE("DAC2 Playback Switch", RT5645_DAC_CTRL
,
482 RT5645_M_DAC_L2_VOL_SFT
, RT5645_M_DAC_R2_VOL_SFT
, 1, 1),
483 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5645_DAC1_DIG_VOL
,
484 RT5645_L_VOL_SFT
, RT5645_R_VOL_SFT
, 175, 0, dac_vol_tlv
),
485 SOC_DOUBLE_TLV("Mono DAC Playback Volume", RT5645_DAC2_DIG_VOL
,
486 RT5645_L_VOL_SFT
, RT5645_R_VOL_SFT
, 175, 0, dac_vol_tlv
),
488 /* IN1/IN2 Control */
489 SOC_SINGLE_TLV("IN1 Boost", RT5645_IN1_CTRL1
,
490 RT5645_BST_SFT1
, 8, 0, bst_tlv
),
491 SOC_SINGLE_TLV("IN2 Boost", RT5645_IN2_CTRL
,
492 RT5645_BST_SFT2
, 8, 0, bst_tlv
),
494 /* INL/INR Volume Control */
495 SOC_DOUBLE_TLV("IN Capture Volume", RT5645_INL1_INR1_VOL
,
496 RT5645_INL_VOL_SFT
, RT5645_INR_VOL_SFT
, 31, 1, in_vol_tlv
),
498 /* ADC Digital Volume Control */
499 SOC_DOUBLE("ADC Capture Switch", RT5645_STO1_ADC_DIG_VOL
,
500 RT5645_L_MUTE_SFT
, RT5645_R_MUTE_SFT
, 1, 1),
501 SOC_DOUBLE_TLV("ADC Capture Volume", RT5645_STO1_ADC_DIG_VOL
,
502 RT5645_L_VOL_SFT
, RT5645_R_VOL_SFT
, 127, 0, adc_vol_tlv
),
503 SOC_DOUBLE("Mono ADC Capture Switch", RT5645_MONO_ADC_DIG_VOL
,
504 RT5645_L_MUTE_SFT
, RT5645_R_MUTE_SFT
, 1, 1),
505 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5645_MONO_ADC_DIG_VOL
,
506 RT5645_L_VOL_SFT
, RT5645_R_VOL_SFT
, 127, 0, adc_vol_tlv
),
508 /* ADC Boost Volume Control */
509 SOC_DOUBLE_TLV("STO1 ADC Boost Gain", RT5645_ADC_BST_VOL1
,
510 RT5645_STO1_ADC_L_BST_SFT
, RT5645_STO1_ADC_R_BST_SFT
, 3, 0,
512 SOC_DOUBLE_TLV("STO2 ADC Boost Gain", RT5645_ADC_BST_VOL1
,
513 RT5645_STO2_ADC_L_BST_SFT
, RT5645_STO2_ADC_R_BST_SFT
, 3, 0,
516 /* I2S2 function select */
517 SOC_SINGLE("I2S2 Func Switch", RT5645_GPIO_CTRL1
, RT5645_I2S2_SEL_SFT
,
521 SOC_ENUM("TDM Adc Slot0 1 Data", rt5645_tdm_adc_slot0_1_enum
),
522 SOC_ENUM("TDM Adc Slot2 3 Data", rt5645_tdm_adc_slot2_3_enum
),
523 SOC_ENUM("TDM Adc Slot4 5 Data", rt5645_tdm_adc_slot4_5_enum
),
524 SOC_ENUM("TDM Adc Slot6 7 Data", rt5645_tdm_adc_slot6_7_enum
),
525 SOC_ENUM("TDM IF1 ADC DATA Sel", rt5645_tdm_adc_sel_enum
),
526 SOC_SINGLE("TDM IF1_DAC1_L Sel", RT5645_TDM_CTRL_3
, 12, 7, 0),
527 SOC_SINGLE("TDM IF1_DAC1_R Sel", RT5645_TDM_CTRL_3
, 8, 7, 0),
528 SOC_SINGLE("TDM IF1_DAC2_L Sel", RT5645_TDM_CTRL_3
, 4, 7, 0),
529 SOC_SINGLE("TDM IF1_DAC2_R Sel", RT5645_TDM_CTRL_3
, 0, 7, 0),
533 * set_dmic_clk - Set parameter of dmic.
536 * @kcontrol: The kcontrol of this widget.
540 static int set_dmic_clk(struct snd_soc_dapm_widget
*w
,
541 struct snd_kcontrol
*kcontrol
, int event
)
543 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
544 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
547 idx
= rl6231_calc_dmic_clk(rt5645
->sysclk
);
550 dev_err(codec
->dev
, "Failed to set DMIC clock\n");
552 snd_soc_update_bits(codec
, RT5645_DMIC_CTRL1
,
553 RT5645_DMIC_CLK_MASK
, idx
<< RT5645_DMIC_CLK_SFT
);
557 static int is_sys_clk_from_pll(struct snd_soc_dapm_widget
*source
,
558 struct snd_soc_dapm_widget
*sink
)
560 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(source
->dapm
);
563 val
= snd_soc_read(codec
, RT5645_GLB_CLK
);
564 val
&= RT5645_SCLK_SRC_MASK
;
565 if (val
== RT5645_SCLK_SRC_PLL1
)
571 static int is_using_asrc(struct snd_soc_dapm_widget
*source
,
572 struct snd_soc_dapm_widget
*sink
)
574 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(source
->dapm
);
575 unsigned int reg
, shift
, val
;
577 switch (source
->shift
) {
606 val
= (snd_soc_read(codec
, reg
) >> shift
) & 0xf;
620 * rt5645_sel_asrc_clk_src - select ASRC clock source for a set of filters
621 * @codec: SoC audio codec device.
622 * @filter_mask: mask of filters.
623 * @clk_src: clock source
625 * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5645 can
626 * only support standard 32fs or 64fs i2s format, ASRC should be enabled to
627 * support special i2s clock format such as Intel's 100fs(100 * sampling rate).
628 * ASRC function will track i2s clock and generate a corresponding system clock
629 * for codec. This function provides an API to select the clock source for a
630 * set of filters specified by the mask. And the codec driver will turn on ASRC
631 * for these filters if ASRC is selected as their clock source.
633 int rt5645_sel_asrc_clk_src(struct snd_soc_codec
*codec
,
634 unsigned int filter_mask
, unsigned int clk_src
)
636 unsigned int asrc2_mask
= 0;
637 unsigned int asrc2_value
= 0;
638 unsigned int asrc3_mask
= 0;
639 unsigned int asrc3_value
= 0;
642 case RT5645_CLK_SEL_SYS
:
643 case RT5645_CLK_SEL_I2S1_ASRC
:
644 case RT5645_CLK_SEL_I2S2_ASRC
:
645 case RT5645_CLK_SEL_SYS2
:
652 if (filter_mask
& RT5645_DA_STEREO_FILTER
) {
653 asrc2_mask
|= RT5645_DA_STO_CLK_SEL_MASK
;
654 asrc2_value
= (asrc2_value
& ~RT5645_DA_STO_CLK_SEL_MASK
)
655 | (clk_src
<< RT5645_DA_STO_CLK_SEL_SFT
);
658 if (filter_mask
& RT5645_DA_MONO_L_FILTER
) {
659 asrc2_mask
|= RT5645_DA_MONOL_CLK_SEL_MASK
;
660 asrc2_value
= (asrc2_value
& ~RT5645_DA_MONOL_CLK_SEL_MASK
)
661 | (clk_src
<< RT5645_DA_MONOL_CLK_SEL_SFT
);
664 if (filter_mask
& RT5645_DA_MONO_R_FILTER
) {
665 asrc2_mask
|= RT5645_DA_MONOR_CLK_SEL_MASK
;
666 asrc2_value
= (asrc2_value
& ~RT5645_DA_MONOR_CLK_SEL_MASK
)
667 | (clk_src
<< RT5645_DA_MONOR_CLK_SEL_SFT
);
670 if (filter_mask
& RT5645_AD_STEREO_FILTER
) {
671 asrc2_mask
|= RT5645_AD_STO1_CLK_SEL_MASK
;
672 asrc2_value
= (asrc2_value
& ~RT5645_AD_STO1_CLK_SEL_MASK
)
673 | (clk_src
<< RT5645_AD_STO1_CLK_SEL_SFT
);
676 if (filter_mask
& RT5645_AD_MONO_L_FILTER
) {
677 asrc3_mask
|= RT5645_AD_MONOL_CLK_SEL_MASK
;
678 asrc3_value
= (asrc3_value
& ~RT5645_AD_MONOL_CLK_SEL_MASK
)
679 | (clk_src
<< RT5645_AD_MONOL_CLK_SEL_SFT
);
682 if (filter_mask
& RT5645_AD_MONO_R_FILTER
) {
683 asrc3_mask
|= RT5645_AD_MONOR_CLK_SEL_MASK
;
684 asrc3_value
= (asrc3_value
& ~RT5645_AD_MONOR_CLK_SEL_MASK
)
685 | (clk_src
<< RT5645_AD_MONOR_CLK_SEL_SFT
);
689 snd_soc_update_bits(codec
, RT5645_ASRC_2
,
690 asrc2_mask
, asrc2_value
);
693 snd_soc_update_bits(codec
, RT5645_ASRC_3
,
694 asrc3_mask
, asrc3_value
);
698 EXPORT_SYMBOL_GPL(rt5645_sel_asrc_clk_src
);
701 static const struct snd_kcontrol_new rt5645_sto1_adc_l_mix
[] = {
702 SOC_DAPM_SINGLE("ADC1 Switch", RT5645_STO1_ADC_MIXER
,
703 RT5645_M_ADC_L1_SFT
, 1, 1),
704 SOC_DAPM_SINGLE("ADC2 Switch", RT5645_STO1_ADC_MIXER
,
705 RT5645_M_ADC_L2_SFT
, 1, 1),
708 static const struct snd_kcontrol_new rt5645_sto1_adc_r_mix
[] = {
709 SOC_DAPM_SINGLE("ADC1 Switch", RT5645_STO1_ADC_MIXER
,
710 RT5645_M_ADC_R1_SFT
, 1, 1),
711 SOC_DAPM_SINGLE("ADC2 Switch", RT5645_STO1_ADC_MIXER
,
712 RT5645_M_ADC_R2_SFT
, 1, 1),
715 static const struct snd_kcontrol_new rt5645_mono_adc_l_mix
[] = {
716 SOC_DAPM_SINGLE("ADC1 Switch", RT5645_MONO_ADC_MIXER
,
717 RT5645_M_MONO_ADC_L1_SFT
, 1, 1),
718 SOC_DAPM_SINGLE("ADC2 Switch", RT5645_MONO_ADC_MIXER
,
719 RT5645_M_MONO_ADC_L2_SFT
, 1, 1),
722 static const struct snd_kcontrol_new rt5645_mono_adc_r_mix
[] = {
723 SOC_DAPM_SINGLE("ADC1 Switch", RT5645_MONO_ADC_MIXER
,
724 RT5645_M_MONO_ADC_R1_SFT
, 1, 1),
725 SOC_DAPM_SINGLE("ADC2 Switch", RT5645_MONO_ADC_MIXER
,
726 RT5645_M_MONO_ADC_R2_SFT
, 1, 1),
729 static const struct snd_kcontrol_new rt5645_dac_l_mix
[] = {
730 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5645_AD_DA_MIXER
,
731 RT5645_M_ADCMIX_L_SFT
, 1, 1),
732 SOC_DAPM_SINGLE("DAC1 Switch", RT5645_AD_DA_MIXER
,
733 RT5645_M_DAC1_L_SFT
, 1, 1),
736 static const struct snd_kcontrol_new rt5645_dac_r_mix
[] = {
737 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5645_AD_DA_MIXER
,
738 RT5645_M_ADCMIX_R_SFT
, 1, 1),
739 SOC_DAPM_SINGLE("DAC1 Switch", RT5645_AD_DA_MIXER
,
740 RT5645_M_DAC1_R_SFT
, 1, 1),
743 static const struct snd_kcontrol_new rt5645_sto_dac_l_mix
[] = {
744 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_STO_DAC_MIXER
,
745 RT5645_M_DAC_L1_SFT
, 1, 1),
746 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_STO_DAC_MIXER
,
747 RT5645_M_DAC_L2_SFT
, 1, 1),
748 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_STO_DAC_MIXER
,
749 RT5645_M_DAC_R1_STO_L_SFT
, 1, 1),
752 static const struct snd_kcontrol_new rt5645_sto_dac_r_mix
[] = {
753 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_STO_DAC_MIXER
,
754 RT5645_M_DAC_R1_SFT
, 1, 1),
755 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_STO_DAC_MIXER
,
756 RT5645_M_DAC_R2_SFT
, 1, 1),
757 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_STO_DAC_MIXER
,
758 RT5645_M_DAC_L1_STO_R_SFT
, 1, 1),
761 static const struct snd_kcontrol_new rt5645_mono_dac_l_mix
[] = {
762 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_MONO_DAC_MIXER
,
763 RT5645_M_DAC_L1_MONO_L_SFT
, 1, 1),
764 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_MONO_DAC_MIXER
,
765 RT5645_M_DAC_L2_MONO_L_SFT
, 1, 1),
766 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_MONO_DAC_MIXER
,
767 RT5645_M_DAC_R2_MONO_L_SFT
, 1, 1),
770 static const struct snd_kcontrol_new rt5645_mono_dac_r_mix
[] = {
771 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_MONO_DAC_MIXER
,
772 RT5645_M_DAC_R1_MONO_R_SFT
, 1, 1),
773 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_MONO_DAC_MIXER
,
774 RT5645_M_DAC_R2_MONO_R_SFT
, 1, 1),
775 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_MONO_DAC_MIXER
,
776 RT5645_M_DAC_L2_MONO_R_SFT
, 1, 1),
779 static const struct snd_kcontrol_new rt5645_dig_l_mix
[] = {
780 SOC_DAPM_SINGLE("Sto DAC Mix L Switch", RT5645_DIG_MIXER
,
781 RT5645_M_STO_L_DAC_L_SFT
, 1, 1),
782 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_DIG_MIXER
,
783 RT5645_M_DAC_L2_DAC_L_SFT
, 1, 1),
784 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_DIG_MIXER
,
785 RT5645_M_DAC_R2_DAC_L_SFT
, 1, 1),
788 static const struct snd_kcontrol_new rt5645_dig_r_mix
[] = {
789 SOC_DAPM_SINGLE("Sto DAC Mix R Switch", RT5645_DIG_MIXER
,
790 RT5645_M_STO_R_DAC_R_SFT
, 1, 1),
791 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_DIG_MIXER
,
792 RT5645_M_DAC_R2_DAC_R_SFT
, 1, 1),
793 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_DIG_MIXER
,
794 RT5645_M_DAC_L2_DAC_R_SFT
, 1, 1),
797 /* Analog Input Mixer */
798 static const struct snd_kcontrol_new rt5645_rec_l_mix
[] = {
799 SOC_DAPM_SINGLE("HPOL Switch", RT5645_REC_L2_MIXER
,
800 RT5645_M_HP_L_RM_L_SFT
, 1, 1),
801 SOC_DAPM_SINGLE("INL Switch", RT5645_REC_L2_MIXER
,
802 RT5645_M_IN_L_RM_L_SFT
, 1, 1),
803 SOC_DAPM_SINGLE("BST2 Switch", RT5645_REC_L2_MIXER
,
804 RT5645_M_BST2_RM_L_SFT
, 1, 1),
805 SOC_DAPM_SINGLE("BST1 Switch", RT5645_REC_L2_MIXER
,
806 RT5645_M_BST1_RM_L_SFT
, 1, 1),
807 SOC_DAPM_SINGLE("OUT MIXL Switch", RT5645_REC_L2_MIXER
,
808 RT5645_M_OM_L_RM_L_SFT
, 1, 1),
811 static const struct snd_kcontrol_new rt5645_rec_r_mix
[] = {
812 SOC_DAPM_SINGLE("HPOR Switch", RT5645_REC_R2_MIXER
,
813 RT5645_M_HP_R_RM_R_SFT
, 1, 1),
814 SOC_DAPM_SINGLE("INR Switch", RT5645_REC_R2_MIXER
,
815 RT5645_M_IN_R_RM_R_SFT
, 1, 1),
816 SOC_DAPM_SINGLE("BST2 Switch", RT5645_REC_R2_MIXER
,
817 RT5645_M_BST2_RM_R_SFT
, 1, 1),
818 SOC_DAPM_SINGLE("BST1 Switch", RT5645_REC_R2_MIXER
,
819 RT5645_M_BST1_RM_R_SFT
, 1, 1),
820 SOC_DAPM_SINGLE("OUT MIXR Switch", RT5645_REC_R2_MIXER
,
821 RT5645_M_OM_R_RM_R_SFT
, 1, 1),
824 static const struct snd_kcontrol_new rt5645_spk_l_mix
[] = {
825 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_SPK_L_MIXER
,
826 RT5645_M_DAC_L1_SM_L_SFT
, 1, 1),
827 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_SPK_L_MIXER
,
828 RT5645_M_DAC_L2_SM_L_SFT
, 1, 1),
829 SOC_DAPM_SINGLE("INL Switch", RT5645_SPK_L_MIXER
,
830 RT5645_M_IN_L_SM_L_SFT
, 1, 1),
831 SOC_DAPM_SINGLE("BST1 Switch", RT5645_SPK_L_MIXER
,
832 RT5645_M_BST1_L_SM_L_SFT
, 1, 1),
835 static const struct snd_kcontrol_new rt5645_spk_r_mix
[] = {
836 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_SPK_R_MIXER
,
837 RT5645_M_DAC_R1_SM_R_SFT
, 1, 1),
838 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_SPK_R_MIXER
,
839 RT5645_M_DAC_R2_SM_R_SFT
, 1, 1),
840 SOC_DAPM_SINGLE("INR Switch", RT5645_SPK_R_MIXER
,
841 RT5645_M_IN_R_SM_R_SFT
, 1, 1),
842 SOC_DAPM_SINGLE("BST2 Switch", RT5645_SPK_R_MIXER
,
843 RT5645_M_BST2_R_SM_R_SFT
, 1, 1),
846 static const struct snd_kcontrol_new rt5645_out_l_mix
[] = {
847 SOC_DAPM_SINGLE("BST1 Switch", RT5645_OUT_L1_MIXER
,
848 RT5645_M_BST1_OM_L_SFT
, 1, 1),
849 SOC_DAPM_SINGLE("INL Switch", RT5645_OUT_L1_MIXER
,
850 RT5645_M_IN_L_OM_L_SFT
, 1, 1),
851 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_OUT_L1_MIXER
,
852 RT5645_M_DAC_L2_OM_L_SFT
, 1, 1),
853 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_OUT_L1_MIXER
,
854 RT5645_M_DAC_L1_OM_L_SFT
, 1, 1),
857 static const struct snd_kcontrol_new rt5645_out_r_mix
[] = {
858 SOC_DAPM_SINGLE("BST2 Switch", RT5645_OUT_R1_MIXER
,
859 RT5645_M_BST2_OM_R_SFT
, 1, 1),
860 SOC_DAPM_SINGLE("INR Switch", RT5645_OUT_R1_MIXER
,
861 RT5645_M_IN_R_OM_R_SFT
, 1, 1),
862 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_OUT_R1_MIXER
,
863 RT5645_M_DAC_R2_OM_R_SFT
, 1, 1),
864 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_OUT_R1_MIXER
,
865 RT5645_M_DAC_R1_OM_R_SFT
, 1, 1),
868 static const struct snd_kcontrol_new rt5645_spo_l_mix
[] = {
869 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_SPO_MIXER
,
870 RT5645_M_DAC_R1_SPM_L_SFT
, 1, 1),
871 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_SPO_MIXER
,
872 RT5645_M_DAC_L1_SPM_L_SFT
, 1, 1),
873 SOC_DAPM_SINGLE("SPKVOL R Switch", RT5645_SPO_MIXER
,
874 RT5645_M_SV_R_SPM_L_SFT
, 1, 1),
875 SOC_DAPM_SINGLE("SPKVOL L Switch", RT5645_SPO_MIXER
,
876 RT5645_M_SV_L_SPM_L_SFT
, 1, 1),
879 static const struct snd_kcontrol_new rt5645_spo_r_mix
[] = {
880 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_SPO_MIXER
,
881 RT5645_M_DAC_R1_SPM_R_SFT
, 1, 1),
882 SOC_DAPM_SINGLE("SPKVOL R Switch", RT5645_SPO_MIXER
,
883 RT5645_M_SV_R_SPM_R_SFT
, 1, 1),
886 static const struct snd_kcontrol_new rt5645_hpo_mix
[] = {
887 SOC_DAPM_SINGLE("DAC1 Switch", RT5645_HPO_MIXER
,
888 RT5645_M_DAC1_HM_SFT
, 1, 1),
889 SOC_DAPM_SINGLE("HPVOL Switch", RT5645_HPO_MIXER
,
890 RT5645_M_HPVOL_HM_SFT
, 1, 1),
893 static const struct snd_kcontrol_new rt5645_hpvoll_mix
[] = {
894 SOC_DAPM_SINGLE("DAC1 Switch", RT5645_HPOMIXL_CTRL
,
895 RT5645_M_DAC1_HV_SFT
, 1, 1),
896 SOC_DAPM_SINGLE("DAC2 Switch", RT5645_HPOMIXL_CTRL
,
897 RT5645_M_DAC2_HV_SFT
, 1, 1),
898 SOC_DAPM_SINGLE("INL Switch", RT5645_HPOMIXL_CTRL
,
899 RT5645_M_IN_HV_SFT
, 1, 1),
900 SOC_DAPM_SINGLE("BST1 Switch", RT5645_HPOMIXL_CTRL
,
901 RT5645_M_BST1_HV_SFT
, 1, 1),
904 static const struct snd_kcontrol_new rt5645_hpvolr_mix
[] = {
905 SOC_DAPM_SINGLE("DAC1 Switch", RT5645_HPOMIXR_CTRL
,
906 RT5645_M_DAC1_HV_SFT
, 1, 1),
907 SOC_DAPM_SINGLE("DAC2 Switch", RT5645_HPOMIXR_CTRL
,
908 RT5645_M_DAC2_HV_SFT
, 1, 1),
909 SOC_DAPM_SINGLE("INR Switch", RT5645_HPOMIXR_CTRL
,
910 RT5645_M_IN_HV_SFT
, 1, 1),
911 SOC_DAPM_SINGLE("BST2 Switch", RT5645_HPOMIXR_CTRL
,
912 RT5645_M_BST2_HV_SFT
, 1, 1),
915 static const struct snd_kcontrol_new rt5645_lout_mix
[] = {
916 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_LOUT_MIXER
,
917 RT5645_M_DAC_L1_LM_SFT
, 1, 1),
918 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_LOUT_MIXER
,
919 RT5645_M_DAC_R1_LM_SFT
, 1, 1),
920 SOC_DAPM_SINGLE("OUTMIX L Switch", RT5645_LOUT_MIXER
,
921 RT5645_M_OV_L_LM_SFT
, 1, 1),
922 SOC_DAPM_SINGLE("OUTMIX R Switch", RT5645_LOUT_MIXER
,
923 RT5645_M_OV_R_LM_SFT
, 1, 1),
926 /*DAC1 L/R source*/ /* MX-29 [9:8] [11:10] */
927 static const char * const rt5645_dac1_src
[] = {
928 "IF1 DAC", "IF2 DAC", "IF3 DAC"
931 static SOC_ENUM_SINGLE_DECL(
932 rt5645_dac1l_enum
, RT5645_AD_DA_MIXER
,
933 RT5645_DAC1_L_SEL_SFT
, rt5645_dac1_src
);
935 static const struct snd_kcontrol_new rt5645_dac1l_mux
=
936 SOC_DAPM_ENUM("DAC1 L source", rt5645_dac1l_enum
);
938 static SOC_ENUM_SINGLE_DECL(
939 rt5645_dac1r_enum
, RT5645_AD_DA_MIXER
,
940 RT5645_DAC1_R_SEL_SFT
, rt5645_dac1_src
);
942 static const struct snd_kcontrol_new rt5645_dac1r_mux
=
943 SOC_DAPM_ENUM("DAC1 R source", rt5645_dac1r_enum
);
945 /*DAC2 L/R source*/ /* MX-1B [6:4] [2:0] */
946 static const char * const rt5645_dac12_src
[] = {
947 "IF1 DAC", "IF2 DAC", "IF3 DAC", "Mono ADC", "VAD_ADC"
950 static SOC_ENUM_SINGLE_DECL(
951 rt5645_dac2l_enum
, RT5645_DAC_CTRL
,
952 RT5645_DAC2_L_SEL_SFT
, rt5645_dac12_src
);
954 static const struct snd_kcontrol_new rt5645_dac_l2_mux
=
955 SOC_DAPM_ENUM("DAC2 L source", rt5645_dac2l_enum
);
957 static const char * const rt5645_dacr2_src
[] = {
958 "IF1 DAC", "IF2 DAC", "IF3 DAC", "Mono ADC", "Haptic"
961 static SOC_ENUM_SINGLE_DECL(
962 rt5645_dac2r_enum
, RT5645_DAC_CTRL
,
963 RT5645_DAC2_R_SEL_SFT
, rt5645_dacr2_src
);
965 static const struct snd_kcontrol_new rt5645_dac_r2_mux
=
966 SOC_DAPM_ENUM("DAC2 R source", rt5645_dac2r_enum
);
970 static const char * const rt5645_inl_src
[] = {
974 static SOC_ENUM_SINGLE_DECL(
975 rt5645_inl_enum
, RT5645_INL1_INR1_VOL
,
976 RT5645_INL_SEL_SFT
, rt5645_inl_src
);
978 static const struct snd_kcontrol_new rt5645_inl_mux
=
979 SOC_DAPM_ENUM("INL source", rt5645_inl_enum
);
981 static const char * const rt5645_inr_src
[] = {
985 static SOC_ENUM_SINGLE_DECL(
986 rt5645_inr_enum
, RT5645_INL1_INR1_VOL
,
987 RT5645_INR_SEL_SFT
, rt5645_inr_src
);
989 static const struct snd_kcontrol_new rt5645_inr_mux
=
990 SOC_DAPM_ENUM("INR source", rt5645_inr_enum
);
992 /* Stereo1 ADC source */
994 static const char * const rt5645_stereo_adc1_src
[] = {
998 static SOC_ENUM_SINGLE_DECL(
999 rt5645_stereo1_adc1_enum
, RT5645_STO1_ADC_MIXER
,
1000 RT5645_ADC_1_SRC_SFT
, rt5645_stereo_adc1_src
);
1002 static const struct snd_kcontrol_new rt5645_sto_adc1_mux
=
1003 SOC_DAPM_ENUM("Stereo1 ADC1 Mux", rt5645_stereo1_adc1_enum
);
1006 static const char * const rt5645_stereo_adc2_src
[] = {
1010 static SOC_ENUM_SINGLE_DECL(
1011 rt5645_stereo1_adc2_enum
, RT5645_STO1_ADC_MIXER
,
1012 RT5645_ADC_2_SRC_SFT
, rt5645_stereo_adc2_src
);
1014 static const struct snd_kcontrol_new rt5645_sto_adc2_mux
=
1015 SOC_DAPM_ENUM("Stereo1 ADC2 Mux", rt5645_stereo1_adc2_enum
);
1018 static const char * const rt5645_stereo_dmic_src
[] = {
1022 static SOC_ENUM_SINGLE_DECL(
1023 rt5645_stereo1_dmic_enum
, RT5645_STO1_ADC_MIXER
,
1024 RT5645_DMIC_SRC_SFT
, rt5645_stereo_dmic_src
);
1026 static const struct snd_kcontrol_new rt5645_sto1_dmic_mux
=
1027 SOC_DAPM_ENUM("Stereo1 DMIC source", rt5645_stereo1_dmic_enum
);
1029 /* Mono ADC source */
1031 static const char * const rt5645_mono_adc_l1_src
[] = {
1032 "Mono DAC MIXL", "ADC"
1035 static SOC_ENUM_SINGLE_DECL(
1036 rt5645_mono_adc_l1_enum
, RT5645_MONO_ADC_MIXER
,
1037 RT5645_MONO_ADC_L1_SRC_SFT
, rt5645_mono_adc_l1_src
);
1039 static const struct snd_kcontrol_new rt5645_mono_adc_l1_mux
=
1040 SOC_DAPM_ENUM("Mono ADC1 left source", rt5645_mono_adc_l1_enum
);
1042 static const char * const rt5645_mono_adc_l2_src
[] = {
1043 "Mono DAC MIXL", "DMIC"
1046 static SOC_ENUM_SINGLE_DECL(
1047 rt5645_mono_adc_l2_enum
, RT5645_MONO_ADC_MIXER
,
1048 RT5645_MONO_ADC_L2_SRC_SFT
, rt5645_mono_adc_l2_src
);
1050 static const struct snd_kcontrol_new rt5645_mono_adc_l2_mux
=
1051 SOC_DAPM_ENUM("Mono ADC2 left source", rt5645_mono_adc_l2_enum
);
1054 static const char * const rt5645_mono_dmic_src
[] = {
1058 static SOC_ENUM_SINGLE_DECL(
1059 rt5645_mono_dmic_l_enum
, RT5645_MONO_ADC_MIXER
,
1060 RT5645_MONO_DMIC_L_SRC_SFT
, rt5645_mono_dmic_src
);
1062 static const struct snd_kcontrol_new rt5645_mono_dmic_l_mux
=
1063 SOC_DAPM_ENUM("Mono DMIC left source", rt5645_mono_dmic_l_enum
);
1065 static SOC_ENUM_SINGLE_DECL(
1066 rt5645_mono_dmic_r_enum
, RT5645_MONO_ADC_MIXER
,
1067 RT5645_MONO_DMIC_R_SRC_SFT
, rt5645_mono_dmic_src
);
1069 static const struct snd_kcontrol_new rt5645_mono_dmic_r_mux
=
1070 SOC_DAPM_ENUM("Mono DMIC Right source", rt5645_mono_dmic_r_enum
);
1072 static const char * const rt5645_mono_adc_r1_src
[] = {
1073 "Mono DAC MIXR", "ADC"
1076 static SOC_ENUM_SINGLE_DECL(
1077 rt5645_mono_adc_r1_enum
, RT5645_MONO_ADC_MIXER
,
1078 RT5645_MONO_ADC_R1_SRC_SFT
, rt5645_mono_adc_r1_src
);
1080 static const struct snd_kcontrol_new rt5645_mono_adc_r1_mux
=
1081 SOC_DAPM_ENUM("Mono ADC1 right source", rt5645_mono_adc_r1_enum
);
1083 static const char * const rt5645_mono_adc_r2_src
[] = {
1084 "Mono DAC MIXR", "DMIC"
1087 static SOC_ENUM_SINGLE_DECL(
1088 rt5645_mono_adc_r2_enum
, RT5645_MONO_ADC_MIXER
,
1089 RT5645_MONO_ADC_R2_SRC_SFT
, rt5645_mono_adc_r2_src
);
1091 static const struct snd_kcontrol_new rt5645_mono_adc_r2_mux
=
1092 SOC_DAPM_ENUM("Mono ADC2 right source", rt5645_mono_adc_r2_enum
);
1095 static const char * const rt5645_if1_adc_in_src
[] = {
1096 "IF_ADC1", "IF_ADC2", "VAD_ADC"
1099 static SOC_ENUM_SINGLE_DECL(
1100 rt5645_if1_adc_in_enum
, RT5645_TDM_CTRL_1
,
1101 RT5645_IF1_ADC_IN_SFT
, rt5645_if1_adc_in_src
);
1103 static const struct snd_kcontrol_new rt5645_if1_adc_in_mux
=
1104 SOC_DAPM_ENUM("IF1 ADC IN source", rt5645_if1_adc_in_enum
);
1107 static const char * const rt5650_a_dac1_src
[] = {
1108 "DAC1", "Stereo DAC Mixer"
1111 static SOC_ENUM_SINGLE_DECL(
1112 rt5650_a_dac1_l_enum
, RT5650_A_DAC_SOUR
,
1113 RT5650_A_DAC1_L_IN_SFT
, rt5650_a_dac1_src
);
1115 static const struct snd_kcontrol_new rt5650_a_dac1_l_mux
=
1116 SOC_DAPM_ENUM("A DAC1 L source", rt5650_a_dac1_l_enum
);
1118 static SOC_ENUM_SINGLE_DECL(
1119 rt5650_a_dac1_r_enum
, RT5650_A_DAC_SOUR
,
1120 RT5650_A_DAC1_R_IN_SFT
, rt5650_a_dac1_src
);
1122 static const struct snd_kcontrol_new rt5650_a_dac1_r_mux
=
1123 SOC_DAPM_ENUM("A DAC1 R source", rt5650_a_dac1_r_enum
);
1126 static const char * const rt5650_a_dac2_src
[] = {
1127 "Stereo DAC Mixer", "Mono DAC Mixer"
1130 static SOC_ENUM_SINGLE_DECL(
1131 rt5650_a_dac2_l_enum
, RT5650_A_DAC_SOUR
,
1132 RT5650_A_DAC2_L_IN_SFT
, rt5650_a_dac2_src
);
1134 static const struct snd_kcontrol_new rt5650_a_dac2_l_mux
=
1135 SOC_DAPM_ENUM("A DAC2 L source", rt5650_a_dac2_l_enum
);
1137 static SOC_ENUM_SINGLE_DECL(
1138 rt5650_a_dac2_r_enum
, RT5650_A_DAC_SOUR
,
1139 RT5650_A_DAC2_R_IN_SFT
, rt5650_a_dac2_src
);
1141 static const struct snd_kcontrol_new rt5650_a_dac2_r_mux
=
1142 SOC_DAPM_ENUM("A DAC2 R source", rt5650_a_dac2_r_enum
);
1145 static const char * const rt5645_if2_adc_in_src
[] = {
1146 "IF_ADC1", "IF_ADC2", "VAD_ADC"
1149 static SOC_ENUM_SINGLE_DECL(
1150 rt5645_if2_adc_in_enum
, RT5645_DIG_INF1_DATA
,
1151 RT5645_IF2_ADC_IN_SFT
, rt5645_if2_adc_in_src
);
1153 static const struct snd_kcontrol_new rt5645_if2_adc_in_mux
=
1154 SOC_DAPM_ENUM("IF2 ADC IN source", rt5645_if2_adc_in_enum
);
1157 static const char * const rt5645_if3_adc_in_src
[] = {
1158 "IF_ADC1", "IF_ADC2", "VAD_ADC"
1161 static SOC_ENUM_SINGLE_DECL(
1162 rt5645_if3_adc_in_enum
, RT5645_DIG_INF1_DATA
,
1163 RT5645_IF3_ADC_IN_SFT
, rt5645_if3_adc_in_src
);
1165 static const struct snd_kcontrol_new rt5645_if3_adc_in_mux
=
1166 SOC_DAPM_ENUM("IF3 ADC IN source", rt5645_if3_adc_in_enum
);
1168 /* MX-31 [15] [13] [11] [9] */
1169 static const char * const rt5645_pdm_src
[] = {
1170 "Mono DAC", "Stereo DAC"
1173 static SOC_ENUM_SINGLE_DECL(
1174 rt5645_pdm1_l_enum
, RT5645_PDM_OUT_CTRL
,
1175 RT5645_PDM1_L_SFT
, rt5645_pdm_src
);
1177 static const struct snd_kcontrol_new rt5645_pdm1_l_mux
=
1178 SOC_DAPM_ENUM("PDM1 L source", rt5645_pdm1_l_enum
);
1180 static SOC_ENUM_SINGLE_DECL(
1181 rt5645_pdm1_r_enum
, RT5645_PDM_OUT_CTRL
,
1182 RT5645_PDM1_R_SFT
, rt5645_pdm_src
);
1184 static const struct snd_kcontrol_new rt5645_pdm1_r_mux
=
1185 SOC_DAPM_ENUM("PDM1 R source", rt5645_pdm1_r_enum
);
1188 static const char * const rt5645_vad_adc_src
[] = {
1189 "Sto1 ADC L", "Mono ADC L", "Mono ADC R"
1192 static SOC_ENUM_SINGLE_DECL(
1193 rt5645_vad_adc_enum
, RT5645_VAD_CTRL4
,
1194 RT5645_VAD_SEL_SFT
, rt5645_vad_adc_src
);
1196 static const struct snd_kcontrol_new rt5645_vad_adc_mux
=
1197 SOC_DAPM_ENUM("VAD ADC source", rt5645_vad_adc_enum
);
1199 static const struct snd_kcontrol_new spk_l_vol_control
=
1200 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_SPK_VOL
,
1201 RT5645_L_MUTE_SFT
, 1, 1);
1203 static const struct snd_kcontrol_new spk_r_vol_control
=
1204 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_SPK_VOL
,
1205 RT5645_R_MUTE_SFT
, 1, 1);
1207 static const struct snd_kcontrol_new hp_l_vol_control
=
1208 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_HP_VOL
,
1209 RT5645_L_MUTE_SFT
, 1, 1);
1211 static const struct snd_kcontrol_new hp_r_vol_control
=
1212 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_HP_VOL
,
1213 RT5645_R_MUTE_SFT
, 1, 1);
1215 static const struct snd_kcontrol_new pdm1_l_vol_control
=
1216 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_PDM_OUT_CTRL
,
1217 RT5645_M_PDM1_L
, 1, 1);
1219 static const struct snd_kcontrol_new pdm1_r_vol_control
=
1220 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_PDM_OUT_CTRL
,
1221 RT5645_M_PDM1_R
, 1, 1);
1223 static void hp_amp_power(struct snd_soc_codec
*codec
, int on
)
1225 static int hp_amp_power_count
;
1226 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
1229 if (hp_amp_power_count
<= 0) {
1230 /* depop parameters */
1231 snd_soc_update_bits(codec
, RT5645_DEPOP_M2
,
1232 RT5645_DEPOP_MASK
, RT5645_DEPOP_MAN
);
1233 snd_soc_write(codec
, RT5645_DEPOP_M1
, 0x000d);
1234 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1235 RT5645_HP_DCC_INT1
, 0x9f01);
1237 /* headphone amp power on */
1238 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1239 RT5645_PWR_FV1
| RT5645_PWR_FV2
, 0);
1240 snd_soc_update_bits(codec
, RT5645_PWR_VOL
,
1241 RT5645_PWR_HV_L
| RT5645_PWR_HV_R
,
1242 RT5645_PWR_HV_L
| RT5645_PWR_HV_R
);
1243 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1244 RT5645_PWR_HP_L
| RT5645_PWR_HP_R
|
1246 RT5645_PWR_HP_L
| RT5645_PWR_HP_R
|
1249 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1250 RT5645_PWR_FV1
| RT5645_PWR_FV2
,
1251 RT5645_PWR_FV1
| RT5645_PWR_FV2
);
1253 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1254 RT5645_HP_CO_MASK
| RT5645_HP_SG_MASK
,
1255 RT5645_HP_CO_EN
| RT5645_HP_SG_EN
);
1256 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1258 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1261 hp_amp_power_count
++;
1263 hp_amp_power_count
--;
1264 if (hp_amp_power_count
<= 0) {
1265 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1266 RT5645_HP_SG_MASK
| RT5645_HP_L_SMT_MASK
|
1267 RT5645_HP_R_SMT_MASK
, RT5645_HP_SG_DIS
|
1268 RT5645_HP_L_SMT_DIS
| RT5645_HP_R_SMT_DIS
);
1269 /* headphone amp power down */
1270 snd_soc_write(codec
, RT5645_DEPOP_M1
, 0x0000);
1271 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1272 RT5645_PWR_HP_L
| RT5645_PWR_HP_R
|
1274 snd_soc_update_bits(codec
, RT5645_DEPOP_M2
,
1275 RT5645_DEPOP_MASK
, 0);
1280 static int rt5645_hp_event(struct snd_soc_dapm_widget
*w
,
1281 struct snd_kcontrol
*kcontrol
, int event
)
1283 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1284 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
1287 case SND_SOC_DAPM_POST_PMU
:
1288 hp_amp_power(codec
, 1);
1289 /* headphone unmute sequence */
1290 if (rt5645
->codec_type
== CODEC_TYPE_RT5650
) {
1291 snd_soc_write(codec
, RT5645_DEPOP_M3
, 0x0737);
1293 snd_soc_update_bits(codec
, RT5645_DEPOP_M3
,
1294 RT5645_CP_FQ1_MASK
| RT5645_CP_FQ2_MASK
|
1296 (RT5645_CP_FQ_192_KHZ
<< RT5645_CP_FQ1_SFT
) |
1297 (RT5645_CP_FQ_12_KHZ
<< RT5645_CP_FQ2_SFT
) |
1298 (RT5645_CP_FQ_192_KHZ
<< RT5645_CP_FQ3_SFT
));
1300 regmap_write(rt5645
->regmap
,
1301 RT5645_PR_BASE
+ RT5645_MAMP_INT_REG2
, 0xfc00);
1302 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1303 RT5645_SMT_TRIG_MASK
, RT5645_SMT_TRIG_EN
);
1304 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1305 RT5645_RSTN_MASK
, RT5645_RSTN_EN
);
1306 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1307 RT5645_RSTN_MASK
| RT5645_HP_L_SMT_MASK
|
1308 RT5645_HP_R_SMT_MASK
, RT5645_RSTN_DIS
|
1309 RT5645_HP_L_SMT_EN
| RT5645_HP_R_SMT_EN
);
1311 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1312 RT5645_HP_SG_MASK
| RT5645_HP_L_SMT_MASK
|
1313 RT5645_HP_R_SMT_MASK
, RT5645_HP_SG_DIS
|
1314 RT5645_HP_L_SMT_DIS
| RT5645_HP_R_SMT_DIS
);
1317 case SND_SOC_DAPM_PRE_PMD
:
1318 /* headphone mute sequence */
1319 if (rt5645
->codec_type
== CODEC_TYPE_RT5650
) {
1320 snd_soc_write(codec
, RT5645_DEPOP_M3
, 0x0737);
1322 snd_soc_update_bits(codec
, RT5645_DEPOP_M3
,
1323 RT5645_CP_FQ1_MASK
| RT5645_CP_FQ2_MASK
|
1325 (RT5645_CP_FQ_96_KHZ
<< RT5645_CP_FQ1_SFT
) |
1326 (RT5645_CP_FQ_12_KHZ
<< RT5645_CP_FQ2_SFT
) |
1327 (RT5645_CP_FQ_96_KHZ
<< RT5645_CP_FQ3_SFT
));
1329 regmap_write(rt5645
->regmap
,
1330 RT5645_PR_BASE
+ RT5645_MAMP_INT_REG2
, 0xfc00);
1331 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1332 RT5645_HP_SG_MASK
, RT5645_HP_SG_EN
);
1333 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1334 RT5645_RSTP_MASK
, RT5645_RSTP_EN
);
1335 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1336 RT5645_RSTP_MASK
| RT5645_HP_L_SMT_MASK
|
1337 RT5645_HP_R_SMT_MASK
, RT5645_RSTP_DIS
|
1338 RT5645_HP_L_SMT_EN
| RT5645_HP_R_SMT_EN
);
1340 hp_amp_power(codec
, 0);
1350 static int rt5645_spk_event(struct snd_soc_dapm_widget
*w
,
1351 struct snd_kcontrol
*kcontrol
, int event
)
1353 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1356 case SND_SOC_DAPM_POST_PMU
:
1357 snd_soc_update_bits(codec
, RT5645_PWR_DIG1
,
1358 RT5645_PWR_CLS_D
| RT5645_PWR_CLS_D_R
|
1360 RT5645_PWR_CLS_D
| RT5645_PWR_CLS_D_R
|
1361 RT5645_PWR_CLS_D_L
);
1364 case SND_SOC_DAPM_PRE_PMD
:
1365 snd_soc_update_bits(codec
, RT5645_PWR_DIG1
,
1366 RT5645_PWR_CLS_D
| RT5645_PWR_CLS_D_R
|
1367 RT5645_PWR_CLS_D_L
, 0);
1377 static int rt5645_lout_event(struct snd_soc_dapm_widget
*w
,
1378 struct snd_kcontrol
*kcontrol
, int event
)
1380 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1383 case SND_SOC_DAPM_POST_PMU
:
1384 hp_amp_power(codec
, 1);
1385 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1386 RT5645_PWR_LM
, RT5645_PWR_LM
);
1387 snd_soc_update_bits(codec
, RT5645_LOUT1
,
1388 RT5645_L_MUTE
| RT5645_R_MUTE
, 0);
1391 case SND_SOC_DAPM_PRE_PMD
:
1392 snd_soc_update_bits(codec
, RT5645_LOUT1
,
1393 RT5645_L_MUTE
| RT5645_R_MUTE
,
1394 RT5645_L_MUTE
| RT5645_R_MUTE
);
1395 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1397 hp_amp_power(codec
, 0);
1407 static int rt5645_bst2_event(struct snd_soc_dapm_widget
*w
,
1408 struct snd_kcontrol
*kcontrol
, int event
)
1410 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1413 case SND_SOC_DAPM_POST_PMU
:
1414 snd_soc_update_bits(codec
, RT5645_PWR_ANLG2
,
1415 RT5645_PWR_BST2_P
, RT5645_PWR_BST2_P
);
1418 case SND_SOC_DAPM_PRE_PMD
:
1419 snd_soc_update_bits(codec
, RT5645_PWR_ANLG2
,
1420 RT5645_PWR_BST2_P
, 0);
1430 static const struct snd_soc_dapm_widget rt5645_dapm_widgets
[] = {
1431 SND_SOC_DAPM_SUPPLY("LDO2", RT5645_PWR_MIXER
,
1432 RT5645_PWR_LDO2_BIT
, 0, NULL
, 0),
1433 SND_SOC_DAPM_SUPPLY("PLL1", RT5645_PWR_ANLG2
,
1434 RT5645_PWR_PLL_BIT
, 0, NULL
, 0),
1436 SND_SOC_DAPM_SUPPLY("JD Power", RT5645_PWR_ANLG2
,
1437 RT5645_PWR_JD1_BIT
, 0, NULL
, 0),
1438 SND_SOC_DAPM_SUPPLY("Mic Det Power", RT5645_PWR_VOL
,
1439 RT5645_PWR_MIC_DET_BIT
, 0, NULL
, 0),
1442 SND_SOC_DAPM_SUPPLY_S("I2S1 ASRC", 1, RT5645_ASRC_1
,
1444 SND_SOC_DAPM_SUPPLY_S("I2S2 ASRC", 1, RT5645_ASRC_1
,
1446 SND_SOC_DAPM_SUPPLY_S("DAC STO ASRC", 1, RT5645_ASRC_1
,
1448 SND_SOC_DAPM_SUPPLY_S("DAC MONO L ASRC", 1, RT5645_ASRC_1
,
1450 SND_SOC_DAPM_SUPPLY_S("DAC MONO R ASRC", 1, RT5645_ASRC_1
,
1452 SND_SOC_DAPM_SUPPLY_S("DMIC STO1 ASRC", 1, RT5645_ASRC_1
,
1454 SND_SOC_DAPM_SUPPLY_S("DMIC MONO L ASRC", 1, RT5645_ASRC_1
,
1456 SND_SOC_DAPM_SUPPLY_S("DMIC MONO R ASRC", 1, RT5645_ASRC_1
,
1458 SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5645_ASRC_1
,
1460 SND_SOC_DAPM_SUPPLY_S("ADC MONO L ASRC", 1, RT5645_ASRC_1
,
1462 SND_SOC_DAPM_SUPPLY_S("ADC MONO R ASRC", 1, RT5645_ASRC_1
,
1467 SND_SOC_DAPM_MICBIAS("micbias1", RT5645_PWR_ANLG2
,
1468 RT5645_PWR_MB1_BIT
, 0),
1469 SND_SOC_DAPM_MICBIAS("micbias2", RT5645_PWR_ANLG2
,
1470 RT5645_PWR_MB2_BIT
, 0),
1472 SND_SOC_DAPM_INPUT("DMIC L1"),
1473 SND_SOC_DAPM_INPUT("DMIC R1"),
1474 SND_SOC_DAPM_INPUT("DMIC L2"),
1475 SND_SOC_DAPM_INPUT("DMIC R2"),
1477 SND_SOC_DAPM_INPUT("IN1P"),
1478 SND_SOC_DAPM_INPUT("IN1N"),
1479 SND_SOC_DAPM_INPUT("IN2P"),
1480 SND_SOC_DAPM_INPUT("IN2N"),
1482 SND_SOC_DAPM_INPUT("Haptic Generator"),
1484 SND_SOC_DAPM_PGA("DMIC1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1485 SND_SOC_DAPM_PGA("DMIC2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1486 SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM
, 0, 0,
1487 set_dmic_clk
, SND_SOC_DAPM_PRE_PMU
),
1488 SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5645_DMIC_CTRL1
,
1489 RT5645_DMIC_1_EN_SFT
, 0, NULL
, 0),
1490 SND_SOC_DAPM_SUPPLY("DMIC2 Power", RT5645_DMIC_CTRL1
,
1491 RT5645_DMIC_2_EN_SFT
, 0, NULL
, 0),
1493 SND_SOC_DAPM_PGA("BST1", RT5645_PWR_ANLG2
,
1494 RT5645_PWR_BST1_BIT
, 0, NULL
, 0),
1495 SND_SOC_DAPM_PGA_E("BST2", RT5645_PWR_ANLG2
,
1496 RT5645_PWR_BST2_BIT
, 0, NULL
, 0, rt5645_bst2_event
,
1497 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
1499 SND_SOC_DAPM_PGA("INL VOL", RT5645_PWR_VOL
,
1500 RT5645_PWR_IN_L_BIT
, 0, NULL
, 0),
1501 SND_SOC_DAPM_PGA("INR VOL", RT5645_PWR_VOL
,
1502 RT5645_PWR_IN_R_BIT
, 0, NULL
, 0),
1504 SND_SOC_DAPM_MIXER("RECMIXL", RT5645_PWR_MIXER
, RT5645_PWR_RM_L_BIT
,
1505 0, rt5645_rec_l_mix
, ARRAY_SIZE(rt5645_rec_l_mix
)),
1506 SND_SOC_DAPM_MIXER("RECMIXR", RT5645_PWR_MIXER
, RT5645_PWR_RM_R_BIT
,
1507 0, rt5645_rec_r_mix
, ARRAY_SIZE(rt5645_rec_r_mix
)),
1509 SND_SOC_DAPM_ADC("ADC L", NULL
, SND_SOC_NOPM
, 0, 0),
1510 SND_SOC_DAPM_ADC("ADC R", NULL
, SND_SOC_NOPM
, 0, 0),
1512 SND_SOC_DAPM_SUPPLY("ADC L power", RT5645_PWR_DIG1
,
1513 RT5645_PWR_ADC_L_BIT
, 0, NULL
, 0),
1514 SND_SOC_DAPM_SUPPLY("ADC R power", RT5645_PWR_DIG1
,
1515 RT5645_PWR_ADC_R_BIT
, 0, NULL
, 0),
1518 SND_SOC_DAPM_MUX("Stereo1 DMIC Mux", SND_SOC_NOPM
, 0, 0,
1519 &rt5645_sto1_dmic_mux
),
1520 SND_SOC_DAPM_MUX("Stereo1 ADC L2 Mux", SND_SOC_NOPM
, 0, 0,
1521 &rt5645_sto_adc2_mux
),
1522 SND_SOC_DAPM_MUX("Stereo1 ADC R2 Mux", SND_SOC_NOPM
, 0, 0,
1523 &rt5645_sto_adc2_mux
),
1524 SND_SOC_DAPM_MUX("Stereo1 ADC L1 Mux", SND_SOC_NOPM
, 0, 0,
1525 &rt5645_sto_adc1_mux
),
1526 SND_SOC_DAPM_MUX("Stereo1 ADC R1 Mux", SND_SOC_NOPM
, 0, 0,
1527 &rt5645_sto_adc1_mux
),
1528 SND_SOC_DAPM_MUX("Mono DMIC L Mux", SND_SOC_NOPM
, 0, 0,
1529 &rt5645_mono_dmic_l_mux
),
1530 SND_SOC_DAPM_MUX("Mono DMIC R Mux", SND_SOC_NOPM
, 0, 0,
1531 &rt5645_mono_dmic_r_mux
),
1532 SND_SOC_DAPM_MUX("Mono ADC L2 Mux", SND_SOC_NOPM
, 0, 0,
1533 &rt5645_mono_adc_l2_mux
),
1534 SND_SOC_DAPM_MUX("Mono ADC L1 Mux", SND_SOC_NOPM
, 0, 0,
1535 &rt5645_mono_adc_l1_mux
),
1536 SND_SOC_DAPM_MUX("Mono ADC R1 Mux", SND_SOC_NOPM
, 0, 0,
1537 &rt5645_mono_adc_r1_mux
),
1538 SND_SOC_DAPM_MUX("Mono ADC R2 Mux", SND_SOC_NOPM
, 0, 0,
1539 &rt5645_mono_adc_r2_mux
),
1542 SND_SOC_DAPM_SUPPLY_S("adc stereo1 filter", 1, RT5645_PWR_DIG2
,
1543 RT5645_PWR_ADC_S1F_BIT
, 0, NULL
, 0),
1544 SND_SOC_DAPM_MIXER_E("Sto1 ADC MIXL", SND_SOC_NOPM
, 0, 0,
1545 rt5645_sto1_adc_l_mix
, ARRAY_SIZE(rt5645_sto1_adc_l_mix
),
1547 SND_SOC_DAPM_MIXER_E("Sto1 ADC MIXR", SND_SOC_NOPM
, 0, 0,
1548 rt5645_sto1_adc_r_mix
, ARRAY_SIZE(rt5645_sto1_adc_r_mix
),
1550 SND_SOC_DAPM_SUPPLY_S("adc mono left filter", 1, RT5645_PWR_DIG2
,
1551 RT5645_PWR_ADC_MF_L_BIT
, 0, NULL
, 0),
1552 SND_SOC_DAPM_MIXER_E("Mono ADC MIXL", SND_SOC_NOPM
, 0, 0,
1553 rt5645_mono_adc_l_mix
, ARRAY_SIZE(rt5645_mono_adc_l_mix
),
1555 SND_SOC_DAPM_SUPPLY_S("adc mono right filter", 1, RT5645_PWR_DIG2
,
1556 RT5645_PWR_ADC_MF_R_BIT
, 0, NULL
, 0),
1557 SND_SOC_DAPM_MIXER_E("Mono ADC MIXR", SND_SOC_NOPM
, 0, 0,
1558 rt5645_mono_adc_r_mix
, ARRAY_SIZE(rt5645_mono_adc_r_mix
),
1562 SND_SOC_DAPM_PGA("Stereo1 ADC MIXL", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1563 SND_SOC_DAPM_PGA("Stereo1 ADC MIXR", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1564 SND_SOC_DAPM_PGA("Sto2 ADC LR MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1565 SND_SOC_DAPM_PGA("VAD_ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1566 SND_SOC_DAPM_PGA("IF_ADC1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1567 SND_SOC_DAPM_PGA("IF_ADC2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1568 SND_SOC_DAPM_PGA("IF1_ADC1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1569 SND_SOC_DAPM_PGA("IF1_ADC2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1570 SND_SOC_DAPM_PGA("IF1_ADC3", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1571 SND_SOC_DAPM_PGA("IF1_ADC4", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1574 SND_SOC_DAPM_MUX("IF1 ADC Mux", SND_SOC_NOPM
,
1575 0, 0, &rt5645_if1_adc_in_mux
),
1576 SND_SOC_DAPM_MUX("IF2 ADC Mux", SND_SOC_NOPM
,
1577 0, 0, &rt5645_if2_adc_in_mux
),
1579 /* Digital Interface */
1580 SND_SOC_DAPM_SUPPLY("I2S1", RT5645_PWR_DIG1
,
1581 RT5645_PWR_I2S1_BIT
, 0, NULL
, 0),
1582 SND_SOC_DAPM_PGA("IF1 DAC1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1583 SND_SOC_DAPM_PGA("IF1 DAC2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1584 SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1585 SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1586 SND_SOC_DAPM_PGA("IF1 DAC2 L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1587 SND_SOC_DAPM_PGA("IF1 DAC2 R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1588 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1589 SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1590 SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1591 SND_SOC_DAPM_SUPPLY("I2S2", RT5645_PWR_DIG1
,
1592 RT5645_PWR_I2S2_BIT
, 0, NULL
, 0),
1593 SND_SOC_DAPM_PGA("IF2 DAC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1594 SND_SOC_DAPM_PGA("IF2 DAC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1595 SND_SOC_DAPM_PGA("IF2 DAC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1596 SND_SOC_DAPM_PGA("IF2 ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1598 /* Digital Interface Select */
1599 SND_SOC_DAPM_MUX("VAD ADC Mux", SND_SOC_NOPM
,
1600 0, 0, &rt5645_vad_adc_mux
),
1602 /* Audio Interface */
1603 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM
, 0, 0),
1604 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM
, 0, 0),
1605 SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Playback", 0, SND_SOC_NOPM
, 0, 0),
1606 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, SND_SOC_NOPM
, 0, 0),
1609 /* DAC mixer before sound effect */
1610 SND_SOC_DAPM_MIXER("DAC1 MIXL", SND_SOC_NOPM
, 0, 0,
1611 rt5645_dac_l_mix
, ARRAY_SIZE(rt5645_dac_l_mix
)),
1612 SND_SOC_DAPM_MIXER("DAC1 MIXR", SND_SOC_NOPM
, 0, 0,
1613 rt5645_dac_r_mix
, ARRAY_SIZE(rt5645_dac_r_mix
)),
1615 /* DAC2 channel Mux */
1616 SND_SOC_DAPM_MUX("DAC L2 Mux", SND_SOC_NOPM
, 0, 0, &rt5645_dac_l2_mux
),
1617 SND_SOC_DAPM_MUX("DAC R2 Mux", SND_SOC_NOPM
, 0, 0, &rt5645_dac_r2_mux
),
1618 SND_SOC_DAPM_PGA("DAC L2 Volume", RT5645_PWR_DIG1
,
1619 RT5645_PWR_DAC_L2_BIT
, 0, NULL
, 0),
1620 SND_SOC_DAPM_PGA("DAC R2 Volume", RT5645_PWR_DIG1
,
1621 RT5645_PWR_DAC_R2_BIT
, 0, NULL
, 0),
1623 SND_SOC_DAPM_MUX("DAC1 L Mux", SND_SOC_NOPM
, 0, 0, &rt5645_dac1l_mux
),
1624 SND_SOC_DAPM_MUX("DAC1 R Mux", SND_SOC_NOPM
, 0, 0, &rt5645_dac1r_mux
),
1627 SND_SOC_DAPM_SUPPLY_S("dac stereo1 filter", 1, RT5645_PWR_DIG2
,
1628 RT5645_PWR_DAC_S1F_BIT
, 0, NULL
, 0),
1629 SND_SOC_DAPM_SUPPLY_S("dac mono left filter", 1, RT5645_PWR_DIG2
,
1630 RT5645_PWR_DAC_MF_L_BIT
, 0, NULL
, 0),
1631 SND_SOC_DAPM_SUPPLY_S("dac mono right filter", 1, RT5645_PWR_DIG2
,
1632 RT5645_PWR_DAC_MF_R_BIT
, 0, NULL
, 0),
1633 SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM
, 0, 0,
1634 rt5645_sto_dac_l_mix
, ARRAY_SIZE(rt5645_sto_dac_l_mix
)),
1635 SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM
, 0, 0,
1636 rt5645_sto_dac_r_mix
, ARRAY_SIZE(rt5645_sto_dac_r_mix
)),
1637 SND_SOC_DAPM_MIXER("Mono DAC MIXL", SND_SOC_NOPM
, 0, 0,
1638 rt5645_mono_dac_l_mix
, ARRAY_SIZE(rt5645_mono_dac_l_mix
)),
1639 SND_SOC_DAPM_MIXER("Mono DAC MIXR", SND_SOC_NOPM
, 0, 0,
1640 rt5645_mono_dac_r_mix
, ARRAY_SIZE(rt5645_mono_dac_r_mix
)),
1641 SND_SOC_DAPM_MIXER("DAC MIXL", SND_SOC_NOPM
, 0, 0,
1642 rt5645_dig_l_mix
, ARRAY_SIZE(rt5645_dig_l_mix
)),
1643 SND_SOC_DAPM_MIXER("DAC MIXR", SND_SOC_NOPM
, 0, 0,
1644 rt5645_dig_r_mix
, ARRAY_SIZE(rt5645_dig_r_mix
)),
1647 SND_SOC_DAPM_DAC("DAC L1", NULL
, RT5645_PWR_DIG1
, RT5645_PWR_DAC_L1_BIT
,
1649 SND_SOC_DAPM_DAC("DAC L2", NULL
, RT5645_PWR_DIG1
, RT5645_PWR_DAC_L2_BIT
,
1651 SND_SOC_DAPM_DAC("DAC R1", NULL
, RT5645_PWR_DIG1
, RT5645_PWR_DAC_R1_BIT
,
1653 SND_SOC_DAPM_DAC("DAC R2", NULL
, RT5645_PWR_DIG1
, RT5645_PWR_DAC_R2_BIT
,
1656 SND_SOC_DAPM_MIXER("SPK MIXL", RT5645_PWR_MIXER
, RT5645_PWR_SM_L_BIT
,
1657 0, rt5645_spk_l_mix
, ARRAY_SIZE(rt5645_spk_l_mix
)),
1658 SND_SOC_DAPM_MIXER("SPK MIXR", RT5645_PWR_MIXER
, RT5645_PWR_SM_R_BIT
,
1659 0, rt5645_spk_r_mix
, ARRAY_SIZE(rt5645_spk_r_mix
)),
1660 SND_SOC_DAPM_MIXER("OUT MIXL", RT5645_PWR_MIXER
, RT5645_PWR_OM_L_BIT
,
1661 0, rt5645_out_l_mix
, ARRAY_SIZE(rt5645_out_l_mix
)),
1662 SND_SOC_DAPM_MIXER("OUT MIXR", RT5645_PWR_MIXER
, RT5645_PWR_OM_R_BIT
,
1663 0, rt5645_out_r_mix
, ARRAY_SIZE(rt5645_out_r_mix
)),
1665 SND_SOC_DAPM_SWITCH("SPKVOL L", RT5645_PWR_VOL
, RT5645_PWR_SV_L_BIT
, 0,
1666 &spk_l_vol_control
),
1667 SND_SOC_DAPM_SWITCH("SPKVOL R", RT5645_PWR_VOL
, RT5645_PWR_SV_R_BIT
, 0,
1668 &spk_r_vol_control
),
1669 SND_SOC_DAPM_MIXER("HPOVOL MIXL", RT5645_PWR_VOL
, RT5645_PWR_HV_L_BIT
,
1670 0, rt5645_hpvoll_mix
, ARRAY_SIZE(rt5645_hpvoll_mix
)),
1671 SND_SOC_DAPM_MIXER("HPOVOL MIXR", RT5645_PWR_VOL
, RT5645_PWR_HV_R_BIT
,
1672 0, rt5645_hpvolr_mix
, ARRAY_SIZE(rt5645_hpvolr_mix
)),
1673 SND_SOC_DAPM_SUPPLY("HPOVOL MIXL Power", RT5645_PWR_MIXER
,
1674 RT5645_PWR_HM_L_BIT
, 0, NULL
, 0),
1675 SND_SOC_DAPM_SUPPLY("HPOVOL MIXR Power", RT5645_PWR_MIXER
,
1676 RT5645_PWR_HM_R_BIT
, 0, NULL
, 0),
1677 SND_SOC_DAPM_PGA("DAC 1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1678 SND_SOC_DAPM_PGA("DAC 2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1679 SND_SOC_DAPM_PGA("HPOVOL", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1680 SND_SOC_DAPM_SWITCH("HPOVOL L", SND_SOC_NOPM
, 0, 0, &hp_l_vol_control
),
1681 SND_SOC_DAPM_SWITCH("HPOVOL R", SND_SOC_NOPM
, 0, 0, &hp_r_vol_control
),
1683 /* HPO/LOUT/Mono Mixer */
1684 SND_SOC_DAPM_MIXER("SPOL MIX", SND_SOC_NOPM
, 0, 0, rt5645_spo_l_mix
,
1685 ARRAY_SIZE(rt5645_spo_l_mix
)),
1686 SND_SOC_DAPM_MIXER("SPOR MIX", SND_SOC_NOPM
, 0, 0, rt5645_spo_r_mix
,
1687 ARRAY_SIZE(rt5645_spo_r_mix
)),
1688 SND_SOC_DAPM_MIXER("HPO MIX", SND_SOC_NOPM
, 0, 0, rt5645_hpo_mix
,
1689 ARRAY_SIZE(rt5645_hpo_mix
)),
1690 SND_SOC_DAPM_MIXER("LOUT MIX", SND_SOC_NOPM
, 0, 0, rt5645_lout_mix
,
1691 ARRAY_SIZE(rt5645_lout_mix
)),
1693 SND_SOC_DAPM_PGA_S("HP amp", 1, SND_SOC_NOPM
, 0, 0, rt5645_hp_event
,
1694 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
1695 SND_SOC_DAPM_PGA_S("LOUT amp", 1, SND_SOC_NOPM
, 0, 0, rt5645_lout_event
,
1696 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
1697 SND_SOC_DAPM_PGA_S("SPK amp", 2, SND_SOC_NOPM
, 0, 0, rt5645_spk_event
,
1698 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
1701 SND_SOC_DAPM_SUPPLY("PDM1 Power", RT5645_PWR_DIG2
, RT5645_PWR_PDM1_BIT
,
1703 SND_SOC_DAPM_MUX("PDM1 L Mux", SND_SOC_NOPM
, 0, 0, &rt5645_pdm1_l_mux
),
1704 SND_SOC_DAPM_MUX("PDM1 R Mux", SND_SOC_NOPM
, 0, 0, &rt5645_pdm1_r_mux
),
1706 SND_SOC_DAPM_SWITCH("PDM1 L", SND_SOC_NOPM
, 0, 0, &pdm1_l_vol_control
),
1707 SND_SOC_DAPM_SWITCH("PDM1 R", SND_SOC_NOPM
, 0, 0, &pdm1_r_vol_control
),
1710 SND_SOC_DAPM_OUTPUT("HPOL"),
1711 SND_SOC_DAPM_OUTPUT("HPOR"),
1712 SND_SOC_DAPM_OUTPUT("LOUTL"),
1713 SND_SOC_DAPM_OUTPUT("LOUTR"),
1714 SND_SOC_DAPM_OUTPUT("PDM1L"),
1715 SND_SOC_DAPM_OUTPUT("PDM1R"),
1716 SND_SOC_DAPM_OUTPUT("SPOL"),
1717 SND_SOC_DAPM_OUTPUT("SPOR"),
1720 static const struct snd_soc_dapm_widget rt5650_specific_dapm_widgets
[] = {
1721 SND_SOC_DAPM_MUX("A DAC1 L Mux", SND_SOC_NOPM
,
1722 0, 0, &rt5650_a_dac1_l_mux
),
1723 SND_SOC_DAPM_MUX("A DAC1 R Mux", SND_SOC_NOPM
,
1724 0, 0, &rt5650_a_dac1_r_mux
),
1725 SND_SOC_DAPM_MUX("A DAC2 L Mux", SND_SOC_NOPM
,
1726 0, 0, &rt5650_a_dac2_l_mux
),
1727 SND_SOC_DAPM_MUX("A DAC2 R Mux", SND_SOC_NOPM
,
1728 0, 0, &rt5650_a_dac2_r_mux
),
1731 static const struct snd_soc_dapm_route rt5645_dapm_routes
[] = {
1732 { "adc stereo1 filter", NULL
, "ADC STO1 ASRC", is_using_asrc
},
1733 { "adc mono left filter", NULL
, "ADC MONO L ASRC", is_using_asrc
},
1734 { "adc mono right filter", NULL
, "ADC MONO R ASRC", is_using_asrc
},
1735 { "dac mono left filter", NULL
, "DAC MONO L ASRC", is_using_asrc
},
1736 { "dac mono right filter", NULL
, "DAC MONO R ASRC", is_using_asrc
},
1737 { "dac stereo1 filter", NULL
, "DAC STO ASRC", is_using_asrc
},
1739 { "I2S1", NULL
, "I2S1 ASRC" },
1740 { "I2S2", NULL
, "I2S2 ASRC" },
1742 { "IN1P", NULL
, "LDO2" },
1743 { "IN2P", NULL
, "LDO2" },
1745 { "DMIC1", NULL
, "DMIC L1" },
1746 { "DMIC1", NULL
, "DMIC R1" },
1747 { "DMIC2", NULL
, "DMIC L2" },
1748 { "DMIC2", NULL
, "DMIC R2" },
1750 { "BST1", NULL
, "IN1P" },
1751 { "BST1", NULL
, "IN1N" },
1752 { "BST1", NULL
, "JD Power" },
1753 { "BST1", NULL
, "Mic Det Power" },
1754 { "BST2", NULL
, "IN2P" },
1755 { "BST2", NULL
, "IN2N" },
1757 { "INL VOL", NULL
, "IN2P" },
1758 { "INR VOL", NULL
, "IN2N" },
1760 { "RECMIXL", "HPOL Switch", "HPOL" },
1761 { "RECMIXL", "INL Switch", "INL VOL" },
1762 { "RECMIXL", "BST2 Switch", "BST2" },
1763 { "RECMIXL", "BST1 Switch", "BST1" },
1764 { "RECMIXL", "OUT MIXL Switch", "OUT MIXL" },
1766 { "RECMIXR", "HPOR Switch", "HPOR" },
1767 { "RECMIXR", "INR Switch", "INR VOL" },
1768 { "RECMIXR", "BST2 Switch", "BST2" },
1769 { "RECMIXR", "BST1 Switch", "BST1" },
1770 { "RECMIXR", "OUT MIXR Switch", "OUT MIXR" },
1772 { "ADC L", NULL
, "RECMIXL" },
1773 { "ADC L", NULL
, "ADC L power" },
1774 { "ADC R", NULL
, "RECMIXR" },
1775 { "ADC R", NULL
, "ADC R power" },
1777 {"DMIC L1", NULL
, "DMIC CLK"},
1778 {"DMIC L1", NULL
, "DMIC1 Power"},
1779 {"DMIC R1", NULL
, "DMIC CLK"},
1780 {"DMIC R1", NULL
, "DMIC1 Power"},
1781 {"DMIC L2", NULL
, "DMIC CLK"},
1782 {"DMIC L2", NULL
, "DMIC2 Power"},
1783 {"DMIC R2", NULL
, "DMIC CLK"},
1784 {"DMIC R2", NULL
, "DMIC2 Power"},
1786 { "Stereo1 DMIC Mux", "DMIC1", "DMIC1" },
1787 { "Stereo1 DMIC Mux", "DMIC2", "DMIC2" },
1788 { "Stereo1 DMIC Mux", NULL
, "DMIC STO1 ASRC" },
1790 { "Mono DMIC L Mux", "DMIC1", "DMIC L1" },
1791 { "Mono DMIC L Mux", "DMIC2", "DMIC L2" },
1792 { "Mono DMIC L Mux", NULL
, "DMIC MONO L ASRC" },
1794 { "Mono DMIC R Mux", "DMIC1", "DMIC R1" },
1795 { "Mono DMIC R Mux", "DMIC2", "DMIC R2" },
1796 { "Mono DMIC R Mux", NULL
, "DMIC MONO R ASRC" },
1798 { "Stereo1 ADC L2 Mux", "DMIC", "Stereo1 DMIC Mux" },
1799 { "Stereo1 ADC L2 Mux", "DAC MIX", "DAC MIXL" },
1800 { "Stereo1 ADC L1 Mux", "ADC", "ADC L" },
1801 { "Stereo1 ADC L1 Mux", "DAC MIX", "DAC MIXL" },
1803 { "Stereo1 ADC R1 Mux", "ADC", "ADC R" },
1804 { "Stereo1 ADC R1 Mux", "DAC MIX", "DAC MIXR" },
1805 { "Stereo1 ADC R2 Mux", "DMIC", "Stereo1 DMIC Mux" },
1806 { "Stereo1 ADC R2 Mux", "DAC MIX", "DAC MIXR" },
1808 { "Mono ADC L2 Mux", "DMIC", "Mono DMIC L Mux" },
1809 { "Mono ADC L2 Mux", "Mono DAC MIXL", "Mono DAC MIXL" },
1810 { "Mono ADC L1 Mux", "Mono DAC MIXL", "Mono DAC MIXL" },
1811 { "Mono ADC L1 Mux", "ADC", "ADC L" },
1813 { "Mono ADC R1 Mux", "Mono DAC MIXR", "Mono DAC MIXR" },
1814 { "Mono ADC R1 Mux", "ADC", "ADC R" },
1815 { "Mono ADC R2 Mux", "DMIC", "Mono DMIC R Mux" },
1816 { "Mono ADC R2 Mux", "Mono DAC MIXR", "Mono DAC MIXR" },
1818 { "Sto1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux" },
1819 { "Sto1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux" },
1820 { "Sto1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux" },
1821 { "Sto1 ADC MIXR", "ADC2 Switch", "Stereo1 ADC R2 Mux" },
1823 { "Stereo1 ADC MIXL", NULL
, "Sto1 ADC MIXL" },
1824 { "Stereo1 ADC MIXL", NULL
, "adc stereo1 filter" },
1825 { "adc stereo1 filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1827 { "Stereo1 ADC MIXR", NULL
, "Sto1 ADC MIXR" },
1828 { "Stereo1 ADC MIXR", NULL
, "adc stereo1 filter" },
1829 { "adc stereo1 filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1831 { "Mono ADC MIXL", "ADC1 Switch", "Mono ADC L1 Mux" },
1832 { "Mono ADC MIXL", "ADC2 Switch", "Mono ADC L2 Mux" },
1833 { "Mono ADC MIXL", NULL
, "adc mono left filter" },
1834 { "adc mono left filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1836 { "Mono ADC MIXR", "ADC1 Switch", "Mono ADC R1 Mux" },
1837 { "Mono ADC MIXR", "ADC2 Switch", "Mono ADC R2 Mux" },
1838 { "Mono ADC MIXR", NULL
, "adc mono right filter" },
1839 { "adc mono right filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1841 { "VAD ADC Mux", "Sto1 ADC L", "Stereo1 ADC MIXL" },
1842 { "VAD ADC Mux", "Mono ADC L", "Mono ADC MIXL" },
1843 { "VAD ADC Mux", "Mono ADC R", "Mono ADC MIXR" },
1845 { "IF_ADC1", NULL
, "Stereo1 ADC MIXL" },
1846 { "IF_ADC1", NULL
, "Stereo1 ADC MIXR" },
1847 { "IF_ADC2", NULL
, "Mono ADC MIXL" },
1848 { "IF_ADC2", NULL
, "Mono ADC MIXR" },
1849 { "VAD_ADC", NULL
, "VAD ADC Mux" },
1851 { "IF1 ADC Mux", "IF_ADC1", "IF_ADC1" },
1852 { "IF1 ADC Mux", "IF_ADC2", "IF_ADC2" },
1853 { "IF1 ADC Mux", "VAD_ADC", "VAD_ADC" },
1855 { "IF2 ADC Mux", "IF_ADC1", "IF_ADC1" },
1856 { "IF2 ADC Mux", "IF_ADC2", "IF_ADC2" },
1857 { "IF2 ADC Mux", "VAD_ADC", "VAD_ADC" },
1859 { "IF1 ADC", NULL
, "I2S1" },
1860 { "IF1 ADC", NULL
, "IF1 ADC Mux" },
1861 { "IF2 ADC", NULL
, "I2S2" },
1862 { "IF2 ADC", NULL
, "IF2 ADC Mux" },
1864 { "AIF1TX", NULL
, "IF1 ADC" },
1865 { "AIF1TX", NULL
, "IF2 ADC" },
1866 { "AIF2TX", NULL
, "IF2 ADC" },
1868 { "IF1 DAC1", NULL
, "AIF1RX" },
1869 { "IF1 DAC2", NULL
, "AIF1RX" },
1870 { "IF2 DAC", NULL
, "AIF2RX" },
1872 { "IF1 DAC1", NULL
, "I2S1" },
1873 { "IF1 DAC2", NULL
, "I2S1" },
1874 { "IF2 DAC", NULL
, "I2S2" },
1876 { "IF1 DAC2 L", NULL
, "IF1 DAC2" },
1877 { "IF1 DAC2 R", NULL
, "IF1 DAC2" },
1878 { "IF1 DAC1 L", NULL
, "IF1 DAC1" },
1879 { "IF1 DAC1 R", NULL
, "IF1 DAC1" },
1880 { "IF2 DAC L", NULL
, "IF2 DAC" },
1881 { "IF2 DAC R", NULL
, "IF2 DAC" },
1883 { "DAC1 L Mux", "IF1 DAC", "IF1 DAC1 L" },
1884 { "DAC1 L Mux", "IF2 DAC", "IF2 DAC L" },
1886 { "DAC1 R Mux", "IF1 DAC", "IF1 DAC1 R" },
1887 { "DAC1 R Mux", "IF2 DAC", "IF2 DAC R" },
1889 { "DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL" },
1890 { "DAC1 MIXL", "DAC1 Switch", "DAC1 L Mux" },
1891 { "DAC1 MIXL", NULL
, "dac stereo1 filter" },
1892 { "DAC1 MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR" },
1893 { "DAC1 MIXR", "DAC1 Switch", "DAC1 R Mux" },
1894 { "DAC1 MIXR", NULL
, "dac stereo1 filter" },
1896 { "DAC L2 Mux", "IF1 DAC", "IF1 DAC2 L" },
1897 { "DAC L2 Mux", "IF2 DAC", "IF2 DAC L" },
1898 { "DAC L2 Mux", "Mono ADC", "Mono ADC MIXL" },
1899 { "DAC L2 Mux", "VAD_ADC", "VAD_ADC" },
1900 { "DAC L2 Volume", NULL
, "DAC L2 Mux" },
1901 { "DAC L2 Volume", NULL
, "dac mono left filter" },
1903 { "DAC R2 Mux", "IF1 DAC", "IF1 DAC2 R" },
1904 { "DAC R2 Mux", "IF2 DAC", "IF2 DAC R" },
1905 { "DAC R2 Mux", "Mono ADC", "Mono ADC MIXR" },
1906 { "DAC R2 Mux", "Haptic", "Haptic Generator" },
1907 { "DAC R2 Volume", NULL
, "DAC R2 Mux" },
1908 { "DAC R2 Volume", NULL
, "dac mono right filter" },
1910 { "Stereo DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" },
1911 { "Stereo DAC MIXL", "DAC R1 Switch", "DAC1 MIXR" },
1912 { "Stereo DAC MIXL", "DAC L2 Switch", "DAC L2 Volume" },
1913 { "Stereo DAC MIXL", NULL
, "dac stereo1 filter" },
1914 { "Stereo DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" },
1915 { "Stereo DAC MIXR", "DAC L1 Switch", "DAC1 MIXL" },
1916 { "Stereo DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" },
1917 { "Stereo DAC MIXR", NULL
, "dac stereo1 filter" },
1919 { "Mono DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" },
1920 { "Mono DAC MIXL", "DAC L2 Switch", "DAC L2 Volume" },
1921 { "Mono DAC MIXL", "DAC R2 Switch", "DAC R2 Volume" },
1922 { "Mono DAC MIXL", NULL
, "dac mono left filter" },
1923 { "Mono DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" },
1924 { "Mono DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" },
1925 { "Mono DAC MIXR", "DAC L2 Switch", "DAC L2 Volume" },
1926 { "Mono DAC MIXR", NULL
, "dac mono right filter" },
1928 { "DAC MIXL", "Sto DAC Mix L Switch", "Stereo DAC MIXL" },
1929 { "DAC MIXL", "DAC L2 Switch", "DAC L2 Volume" },
1930 { "DAC MIXL", "DAC R2 Switch", "DAC R2 Volume" },
1931 { "DAC MIXR", "Sto DAC Mix R Switch", "Stereo DAC MIXR" },
1932 { "DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" },
1933 { "DAC MIXR", "DAC L2 Switch", "DAC L2 Volume" },
1935 { "DAC L1", NULL
, "PLL1", is_sys_clk_from_pll
},
1936 { "DAC R1", NULL
, "PLL1", is_sys_clk_from_pll
},
1937 { "DAC L2", NULL
, "PLL1", is_sys_clk_from_pll
},
1938 { "DAC R2", NULL
, "PLL1", is_sys_clk_from_pll
},
1940 { "SPK MIXL", "BST1 Switch", "BST1" },
1941 { "SPK MIXL", "INL Switch", "INL VOL" },
1942 { "SPK MIXL", "DAC L1 Switch", "DAC L1" },
1943 { "SPK MIXL", "DAC L2 Switch", "DAC L2" },
1944 { "SPK MIXR", "BST2 Switch", "BST2" },
1945 { "SPK MIXR", "INR Switch", "INR VOL" },
1946 { "SPK MIXR", "DAC R1 Switch", "DAC R1" },
1947 { "SPK MIXR", "DAC R2 Switch", "DAC R2" },
1949 { "OUT MIXL", "BST1 Switch", "BST1" },
1950 { "OUT MIXL", "INL Switch", "INL VOL" },
1951 { "OUT MIXL", "DAC L2 Switch", "DAC L2" },
1952 { "OUT MIXL", "DAC L1 Switch", "DAC L1" },
1954 { "OUT MIXR", "BST2 Switch", "BST2" },
1955 { "OUT MIXR", "INR Switch", "INR VOL" },
1956 { "OUT MIXR", "DAC R2 Switch", "DAC R2" },
1957 { "OUT MIXR", "DAC R1 Switch", "DAC R1" },
1959 { "HPOVOL MIXL", "DAC1 Switch", "DAC L1" },
1960 { "HPOVOL MIXL", "DAC2 Switch", "DAC L2" },
1961 { "HPOVOL MIXL", "INL Switch", "INL VOL" },
1962 { "HPOVOL MIXL", "BST1 Switch", "BST1" },
1963 { "HPOVOL MIXL", NULL
, "HPOVOL MIXL Power" },
1964 { "HPOVOL MIXR", "DAC1 Switch", "DAC R1" },
1965 { "HPOVOL MIXR", "DAC2 Switch", "DAC R2" },
1966 { "HPOVOL MIXR", "INR Switch", "INR VOL" },
1967 { "HPOVOL MIXR", "BST2 Switch", "BST2" },
1968 { "HPOVOL MIXR", NULL
, "HPOVOL MIXR Power" },
1970 { "DAC 2", NULL
, "DAC L2" },
1971 { "DAC 2", NULL
, "DAC R2" },
1972 { "DAC 1", NULL
, "DAC L1" },
1973 { "DAC 1", NULL
, "DAC R1" },
1974 { "HPOVOL L", "Switch", "HPOVOL MIXL" },
1975 { "HPOVOL R", "Switch", "HPOVOL MIXR" },
1976 { "HPOVOL", NULL
, "HPOVOL L" },
1977 { "HPOVOL", NULL
, "HPOVOL R" },
1978 { "HPO MIX", "DAC1 Switch", "DAC 1" },
1979 { "HPO MIX", "HPVOL Switch", "HPOVOL" },
1981 { "SPKVOL L", "Switch", "SPK MIXL" },
1982 { "SPKVOL R", "Switch", "SPK MIXR" },
1984 { "SPOL MIX", "DAC R1 Switch", "DAC R1" },
1985 { "SPOL MIX", "DAC L1 Switch", "DAC L1" },
1986 { "SPOL MIX", "SPKVOL R Switch", "SPKVOL R" },
1987 { "SPOL MIX", "SPKVOL L Switch", "SPKVOL L" },
1988 { "SPOR MIX", "DAC R1 Switch", "DAC R1" },
1989 { "SPOR MIX", "SPKVOL R Switch", "SPKVOL R" },
1991 { "LOUT MIX", "DAC L1 Switch", "DAC L1" },
1992 { "LOUT MIX", "DAC R1 Switch", "DAC R1" },
1993 { "LOUT MIX", "OUTMIX L Switch", "OUT MIXL" },
1994 { "LOUT MIX", "OUTMIX R Switch", "OUT MIXR" },
1996 { "PDM1 L Mux", "Stereo DAC", "Stereo DAC MIXL" },
1997 { "PDM1 L Mux", "Mono DAC", "Mono DAC MIXL" },
1998 { "PDM1 L Mux", NULL
, "PDM1 Power" },
1999 { "PDM1 R Mux", "Stereo DAC", "Stereo DAC MIXR" },
2000 { "PDM1 R Mux", "Mono DAC", "Mono DAC MIXR" },
2001 { "PDM1 R Mux", NULL
, "PDM1 Power" },
2003 { "HP amp", NULL
, "HPO MIX" },
2004 { "HP amp", NULL
, "JD Power" },
2005 { "HP amp", NULL
, "Mic Det Power" },
2006 { "HP amp", NULL
, "LDO2" },
2007 { "HPOL", NULL
, "HP amp" },
2008 { "HPOR", NULL
, "HP amp" },
2010 { "LOUT amp", NULL
, "LOUT MIX" },
2011 { "LOUTL", NULL
, "LOUT amp" },
2012 { "LOUTR", NULL
, "LOUT amp" },
2014 { "PDM1 L", "Switch", "PDM1 L Mux" },
2015 { "PDM1 R", "Switch", "PDM1 R Mux" },
2017 { "PDM1L", NULL
, "PDM1 L" },
2018 { "PDM1R", NULL
, "PDM1 R" },
2020 { "SPK amp", NULL
, "SPOL MIX" },
2021 { "SPK amp", NULL
, "SPOR MIX" },
2022 { "SPOL", NULL
, "SPK amp" },
2023 { "SPOR", NULL
, "SPK amp" },
2026 static const struct snd_soc_dapm_route rt5650_specific_dapm_routes
[] = {
2027 { "A DAC1 L Mux", "DAC1", "DAC1 MIXL"},
2028 { "A DAC1 L Mux", "Stereo DAC Mixer", "Stereo DAC MIXL"},
2029 { "A DAC1 R Mux", "DAC1", "DAC1 MIXR"},
2030 { "A DAC1 R Mux", "Stereo DAC Mixer", "Stereo DAC MIXR"},
2032 { "A DAC2 L Mux", "Stereo DAC Mixer", "Stereo DAC MIXL"},
2033 { "A DAC2 L Mux", "Mono DAC Mixer", "Mono DAC MIXL"},
2034 { "A DAC2 R Mux", "Stereo DAC Mixer", "Stereo DAC MIXR"},
2035 { "A DAC2 R Mux", "Mono DAC Mixer", "Mono DAC MIXR"},
2037 { "DAC L1", NULL
, "A DAC1 L Mux" },
2038 { "DAC R1", NULL
, "A DAC1 R Mux" },
2039 { "DAC L2", NULL
, "A DAC2 L Mux" },
2040 { "DAC R2", NULL
, "A DAC2 R Mux" },
2043 static const struct snd_soc_dapm_route rt5645_specific_dapm_routes
[] = {
2044 { "DAC L1", NULL
, "Stereo DAC MIXL" },
2045 { "DAC R1", NULL
, "Stereo DAC MIXR" },
2046 { "DAC L2", NULL
, "Mono DAC MIXL" },
2047 { "DAC R2", NULL
, "Mono DAC MIXR" },
2050 static int rt5645_hw_params(struct snd_pcm_substream
*substream
,
2051 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
2053 struct snd_soc_codec
*codec
= dai
->codec
;
2054 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2055 unsigned int val_len
= 0, val_clk
, mask_clk
, dl_sft
;
2056 int pre_div
, bclk_ms
, frame_size
;
2058 rt5645
->lrck
[dai
->id
] = params_rate(params
);
2059 pre_div
= rl6231_get_clk_info(rt5645
->sysclk
, rt5645
->lrck
[dai
->id
]);
2061 dev_err(codec
->dev
, "Unsupported clock setting\n");
2064 frame_size
= snd_soc_params_to_frame_size(params
);
2065 if (frame_size
< 0) {
2066 dev_err(codec
->dev
, "Unsupported frame size: %d\n", frame_size
);
2070 switch (rt5645
->codec_type
) {
2071 case CODEC_TYPE_RT5650
:
2079 bclk_ms
= frame_size
> 32;
2080 rt5645
->bclk
[dai
->id
] = rt5645
->lrck
[dai
->id
] * (32 << bclk_ms
);
2082 dev_dbg(dai
->dev
, "bclk is %dHz and lrck is %dHz\n",
2083 rt5645
->bclk
[dai
->id
], rt5645
->lrck
[dai
->id
]);
2084 dev_dbg(dai
->dev
, "bclk_ms is %d and pre_div is %d for iis %d\n",
2085 bclk_ms
, pre_div
, dai
->id
);
2087 switch (params_width(params
)) {
2105 mask_clk
= RT5645_I2S_BCLK_MS1_MASK
| RT5645_I2S_PD1_MASK
;
2106 val_clk
= bclk_ms
<< RT5645_I2S_BCLK_MS1_SFT
|
2107 pre_div
<< RT5645_I2S_PD1_SFT
;
2108 snd_soc_update_bits(codec
, RT5645_I2S1_SDP
,
2109 (0x3 << dl_sft
), (val_len
<< dl_sft
));
2110 snd_soc_update_bits(codec
, RT5645_ADDA_CLK1
, mask_clk
, val_clk
);
2113 mask_clk
= RT5645_I2S_BCLK_MS2_MASK
| RT5645_I2S_PD2_MASK
;
2114 val_clk
= bclk_ms
<< RT5645_I2S_BCLK_MS2_SFT
|
2115 pre_div
<< RT5645_I2S_PD2_SFT
;
2116 snd_soc_update_bits(codec
, RT5645_I2S2_SDP
,
2117 (0x3 << dl_sft
), (val_len
<< dl_sft
));
2118 snd_soc_update_bits(codec
, RT5645_ADDA_CLK1
, mask_clk
, val_clk
);
2121 dev_err(codec
->dev
, "Invalid dai->id: %d\n", dai
->id
);
2128 static int rt5645_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
2130 struct snd_soc_codec
*codec
= dai
->codec
;
2131 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2132 unsigned int reg_val
= 0, pol_sft
;
2134 switch (rt5645
->codec_type
) {
2135 case CODEC_TYPE_RT5650
:
2143 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
2144 case SND_SOC_DAIFMT_CBM_CFM
:
2145 rt5645
->master
[dai
->id
] = 1;
2147 case SND_SOC_DAIFMT_CBS_CFS
:
2148 reg_val
|= RT5645_I2S_MS_S
;
2149 rt5645
->master
[dai
->id
] = 0;
2155 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
2156 case SND_SOC_DAIFMT_NB_NF
:
2158 case SND_SOC_DAIFMT_IB_NF
:
2159 reg_val
|= (1 << pol_sft
);
2165 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
2166 case SND_SOC_DAIFMT_I2S
:
2168 case SND_SOC_DAIFMT_LEFT_J
:
2169 reg_val
|= RT5645_I2S_DF_LEFT
;
2171 case SND_SOC_DAIFMT_DSP_A
:
2172 reg_val
|= RT5645_I2S_DF_PCM_A
;
2174 case SND_SOC_DAIFMT_DSP_B
:
2175 reg_val
|= RT5645_I2S_DF_PCM_B
;
2182 snd_soc_update_bits(codec
, RT5645_I2S1_SDP
,
2183 RT5645_I2S_MS_MASK
| (1 << pol_sft
) |
2184 RT5645_I2S_DF_MASK
, reg_val
);
2187 snd_soc_update_bits(codec
, RT5645_I2S2_SDP
,
2188 RT5645_I2S_MS_MASK
| (1 << pol_sft
) |
2189 RT5645_I2S_DF_MASK
, reg_val
);
2192 dev_err(codec
->dev
, "Invalid dai->id: %d\n", dai
->id
);
2198 static int rt5645_set_dai_sysclk(struct snd_soc_dai
*dai
,
2199 int clk_id
, unsigned int freq
, int dir
)
2201 struct snd_soc_codec
*codec
= dai
->codec
;
2202 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2203 unsigned int reg_val
= 0;
2205 if (freq
== rt5645
->sysclk
&& clk_id
== rt5645
->sysclk_src
)
2209 case RT5645_SCLK_S_MCLK
:
2210 reg_val
|= RT5645_SCLK_SRC_MCLK
;
2212 case RT5645_SCLK_S_PLL1
:
2213 reg_val
|= RT5645_SCLK_SRC_PLL1
;
2215 case RT5645_SCLK_S_RCCLK
:
2216 reg_val
|= RT5645_SCLK_SRC_RCCLK
;
2219 dev_err(codec
->dev
, "Invalid clock id (%d)\n", clk_id
);
2222 snd_soc_update_bits(codec
, RT5645_GLB_CLK
,
2223 RT5645_SCLK_SRC_MASK
, reg_val
);
2224 rt5645
->sysclk
= freq
;
2225 rt5645
->sysclk_src
= clk_id
;
2227 dev_dbg(dai
->dev
, "Sysclk is %dHz and clock id is %d\n", freq
, clk_id
);
2232 static int rt5645_set_dai_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
2233 unsigned int freq_in
, unsigned int freq_out
)
2235 struct snd_soc_codec
*codec
= dai
->codec
;
2236 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2237 struct rl6231_pll_code pll_code
;
2240 if (source
== rt5645
->pll_src
&& freq_in
== rt5645
->pll_in
&&
2241 freq_out
== rt5645
->pll_out
)
2244 if (!freq_in
|| !freq_out
) {
2245 dev_dbg(codec
->dev
, "PLL disabled\n");
2248 rt5645
->pll_out
= 0;
2249 snd_soc_update_bits(codec
, RT5645_GLB_CLK
,
2250 RT5645_SCLK_SRC_MASK
, RT5645_SCLK_SRC_MCLK
);
2255 case RT5645_PLL1_S_MCLK
:
2256 snd_soc_update_bits(codec
, RT5645_GLB_CLK
,
2257 RT5645_PLL1_SRC_MASK
, RT5645_PLL1_SRC_MCLK
);
2259 case RT5645_PLL1_S_BCLK1
:
2260 case RT5645_PLL1_S_BCLK2
:
2263 snd_soc_update_bits(codec
, RT5645_GLB_CLK
,
2264 RT5645_PLL1_SRC_MASK
, RT5645_PLL1_SRC_BCLK1
);
2267 snd_soc_update_bits(codec
, RT5645_GLB_CLK
,
2268 RT5645_PLL1_SRC_MASK
, RT5645_PLL1_SRC_BCLK2
);
2271 dev_err(codec
->dev
, "Invalid dai->id: %d\n", dai
->id
);
2276 dev_err(codec
->dev
, "Unknown PLL source %d\n", source
);
2280 ret
= rl6231_pll_calc(freq_in
, freq_out
, &pll_code
);
2282 dev_err(codec
->dev
, "Unsupport input clock %d\n", freq_in
);
2286 dev_dbg(codec
->dev
, "bypass=%d m=%d n=%d k=%d\n",
2287 pll_code
.m_bp
, (pll_code
.m_bp
? 0 : pll_code
.m_code
),
2288 pll_code
.n_code
, pll_code
.k_code
);
2290 snd_soc_write(codec
, RT5645_PLL_CTRL1
,
2291 pll_code
.n_code
<< RT5645_PLL_N_SFT
| pll_code
.k_code
);
2292 snd_soc_write(codec
, RT5645_PLL_CTRL2
,
2293 (pll_code
.m_bp
? 0 : pll_code
.m_code
) << RT5645_PLL_M_SFT
|
2294 pll_code
.m_bp
<< RT5645_PLL_M_BP_SFT
);
2296 rt5645
->pll_in
= freq_in
;
2297 rt5645
->pll_out
= freq_out
;
2298 rt5645
->pll_src
= source
;
2303 static int rt5645_set_tdm_slot(struct snd_soc_dai
*dai
, unsigned int tx_mask
,
2304 unsigned int rx_mask
, int slots
, int slot_width
)
2306 struct snd_soc_codec
*codec
= dai
->codec
;
2307 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2308 unsigned int i_slot_sft
, o_slot_sft
, i_width_sht
, o_width_sht
, en_sft
;
2309 unsigned int mask
, val
= 0;
2311 switch (rt5645
->codec_type
) {
2312 case CODEC_TYPE_RT5650
:
2322 i_slot_sft
= o_slot_sft
= 12;
2323 i_width_sht
= o_width_sht
= 10;
2327 if (rx_mask
|| tx_mask
) {
2328 val
|= (1 << en_sft
);
2329 if (rt5645
->codec_type
== CODEC_TYPE_RT5645
)
2330 snd_soc_update_bits(codec
, RT5645_BASS_BACK
,
2331 RT5645_G_BB_BST_MASK
, RT5645_G_BB_BST_25DB
);
2336 val
|= (1 << i_slot_sft
) | (1 << o_slot_sft
);
2339 val
|= (2 << i_slot_sft
) | (2 << o_slot_sft
);
2342 val
|= (3 << i_slot_sft
) | (3 << o_slot_sft
);
2349 switch (slot_width
) {
2351 val
|= (1 << i_width_sht
) | (1 << o_width_sht
);
2354 val
|= (2 << i_width_sht
) | (2 << o_width_sht
);
2357 val
|= (3 << i_width_sht
) | (3 << o_width_sht
);
2364 snd_soc_update_bits(codec
, RT5645_TDM_CTRL_1
, mask
, val
);
2369 static int rt5645_set_bias_level(struct snd_soc_codec
*codec
,
2370 enum snd_soc_bias_level level
)
2373 case SND_SOC_BIAS_PREPARE
:
2374 if (SND_SOC_BIAS_STANDBY
== codec
->dapm
.bias_level
) {
2375 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
2376 RT5645_PWR_VREF1
| RT5645_PWR_MB
|
2377 RT5645_PWR_BG
| RT5645_PWR_VREF2
,
2378 RT5645_PWR_VREF1
| RT5645_PWR_MB
|
2379 RT5645_PWR_BG
| RT5645_PWR_VREF2
);
2381 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
2382 RT5645_PWR_FV1
| RT5645_PWR_FV2
,
2383 RT5645_PWR_FV1
| RT5645_PWR_FV2
);
2384 snd_soc_update_bits(codec
, RT5645_GEN_CTRL1
,
2385 RT5645_DIG_GATE_CTRL
, RT5645_DIG_GATE_CTRL
);
2389 case SND_SOC_BIAS_STANDBY
:
2390 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
2391 RT5645_PWR_VREF1
| RT5645_PWR_MB
|
2392 RT5645_PWR_BG
| RT5645_PWR_VREF2
,
2393 RT5645_PWR_VREF1
| RT5645_PWR_MB
|
2394 RT5645_PWR_BG
| RT5645_PWR_VREF2
);
2395 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
2396 RT5645_PWR_FV1
| RT5645_PWR_FV2
,
2397 RT5645_PWR_FV1
| RT5645_PWR_FV2
);
2400 case SND_SOC_BIAS_OFF
:
2401 snd_soc_write(codec
, RT5645_DEPOP_M2
, 0x1100);
2402 snd_soc_update_bits(codec
, RT5645_GEN_CTRL1
,
2403 RT5645_DIG_GATE_CTRL
, 0);
2404 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
2405 RT5645_PWR_VREF1
| RT5645_PWR_MB
|
2406 RT5645_PWR_BG
| RT5645_PWR_VREF2
|
2407 RT5645_PWR_FV1
| RT5645_PWR_FV2
, 0x0);
2413 codec
->dapm
.bias_level
= level
;
2418 static int rt5645_jack_detect(struct snd_soc_codec
*codec
)
2420 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2421 int gpio_state
, jack_type
= 0;
2424 if (!gpio_is_valid(rt5645
->pdata
.hp_det_gpio
)) {
2425 dev_err(codec
->dev
, "invalid gpio\n");
2428 gpio_state
= gpio_get_value(rt5645
->pdata
.hp_det_gpio
);
2430 dev_dbg(codec
->dev
, "gpio = %d(%d)\n", rt5645
->pdata
.hp_det_gpio
,
2433 if ((rt5645
->pdata
.gpio_hp_det_active_high
&& gpio_state
) ||
2434 (!rt5645
->pdata
.gpio_hp_det_active_high
&& !gpio_state
)) {
2435 snd_soc_dapm_force_enable_pin(&codec
->dapm
, "micbias1");
2436 snd_soc_dapm_force_enable_pin(&codec
->dapm
, "micbias2");
2437 snd_soc_dapm_force_enable_pin(&codec
->dapm
, "LDO2");
2438 snd_soc_dapm_force_enable_pin(&codec
->dapm
, "Mic Det Power");
2439 snd_soc_dapm_sync(&codec
->dapm
);
2441 snd_soc_write(codec
, RT5645_IN1_CTRL1
, 0x0006);
2442 snd_soc_write(codec
, RT5645_JD_CTRL3
, 0x00b0);
2444 snd_soc_update_bits(codec
, RT5645_IN1_CTRL2
,
2445 RT5645_CBJ_MN_JD
, 0);
2446 snd_soc_update_bits(codec
, RT5645_IN1_CTRL2
,
2447 RT5645_CBJ_MN_JD
, RT5645_CBJ_MN_JD
);
2450 val
= snd_soc_read(codec
, RT5645_IN1_CTRL3
) & 0x7;
2451 dev_dbg(codec
->dev
, "val = %d\n", val
);
2453 if (val
== 1 || val
== 2)
2454 jack_type
= SND_JACK_HEADSET
;
2456 jack_type
= SND_JACK_HEADPHONE
;
2458 snd_soc_dapm_disable_pin(&codec
->dapm
, "micbias1");
2459 snd_soc_dapm_disable_pin(&codec
->dapm
, "micbias2");
2460 if (rt5645
->pdata
.jd_mode
== 0)
2461 snd_soc_dapm_disable_pin(&codec
->dapm
, "LDO2");
2462 snd_soc_dapm_disable_pin(&codec
->dapm
, "Mic Det Power");
2463 snd_soc_dapm_sync(&codec
->dapm
);
2466 snd_soc_jack_report(rt5645
->hp_jack
, jack_type
, SND_JACK_HEADPHONE
);
2467 snd_soc_jack_report(rt5645
->mic_jack
, jack_type
, SND_JACK_MICROPHONE
);
2471 int rt5645_set_jack_detect(struct snd_soc_codec
*codec
,
2472 struct snd_soc_jack
*hp_jack
, struct snd_soc_jack
*mic_jack
)
2474 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2476 rt5645
->hp_jack
= hp_jack
;
2477 rt5645
->mic_jack
= mic_jack
;
2478 rt5645_jack_detect(codec
);
2482 EXPORT_SYMBOL_GPL(rt5645_set_jack_detect
);
2484 static void rt5645_jack_detect_work(struct work_struct
*work
)
2486 struct rt5645_priv
*rt5645
=
2487 container_of(work
, struct rt5645_priv
, jack_detect_work
.work
);
2489 rt5645_jack_detect(rt5645
->codec
);
2492 static irqreturn_t
rt5645_irq(int irq
, void *data
)
2494 struct rt5645_priv
*rt5645
= data
;
2496 queue_delayed_work(system_power_efficient_wq
,
2497 &rt5645
->jack_detect_work
, msecs_to_jiffies(250));
2502 static int rt5645_probe(struct snd_soc_codec
*codec
)
2504 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2506 rt5645
->codec
= codec
;
2508 switch (rt5645
->codec_type
) {
2509 case CODEC_TYPE_RT5645
:
2510 snd_soc_dapm_add_routes(&codec
->dapm
,
2511 rt5645_specific_dapm_routes
,
2512 ARRAY_SIZE(rt5645_specific_dapm_routes
));
2514 case CODEC_TYPE_RT5650
:
2515 snd_soc_dapm_new_controls(&codec
->dapm
,
2516 rt5650_specific_dapm_widgets
,
2517 ARRAY_SIZE(rt5650_specific_dapm_widgets
));
2518 snd_soc_dapm_add_routes(&codec
->dapm
,
2519 rt5650_specific_dapm_routes
,
2520 ARRAY_SIZE(rt5650_specific_dapm_routes
));
2524 rt5645_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
2526 snd_soc_update_bits(codec
, RT5645_CHARGE_PUMP
, 0x0300, 0x0200);
2528 /* for JD function */
2529 if (rt5645
->pdata
.en_jd_func
) {
2530 snd_soc_dapm_force_enable_pin(&codec
->dapm
, "JD Power");
2531 snd_soc_dapm_force_enable_pin(&codec
->dapm
, "LDO2");
2532 snd_soc_dapm_sync(&codec
->dapm
);
2538 static int rt5645_remove(struct snd_soc_codec
*codec
)
2540 rt5645_reset(codec
);
2545 static int rt5645_suspend(struct snd_soc_codec
*codec
)
2547 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2549 regcache_cache_only(rt5645
->regmap
, true);
2550 regcache_mark_dirty(rt5645
->regmap
);
2555 static int rt5645_resume(struct snd_soc_codec
*codec
)
2557 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2559 regcache_cache_only(rt5645
->regmap
, false);
2560 regcache_sync(rt5645
->regmap
);
2565 #define rt5645_suspend NULL
2566 #define rt5645_resume NULL
2569 #define RT5645_STEREO_RATES SNDRV_PCM_RATE_8000_96000
2570 #define RT5645_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
2571 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
2573 static struct snd_soc_dai_ops rt5645_aif_dai_ops
= {
2574 .hw_params
= rt5645_hw_params
,
2575 .set_fmt
= rt5645_set_dai_fmt
,
2576 .set_sysclk
= rt5645_set_dai_sysclk
,
2577 .set_tdm_slot
= rt5645_set_tdm_slot
,
2578 .set_pll
= rt5645_set_dai_pll
,
2581 static struct snd_soc_dai_driver rt5645_dai
[] = {
2583 .name
= "rt5645-aif1",
2586 .stream_name
= "AIF1 Playback",
2589 .rates
= RT5645_STEREO_RATES
,
2590 .formats
= RT5645_FORMATS
,
2593 .stream_name
= "AIF1 Capture",
2596 .rates
= RT5645_STEREO_RATES
,
2597 .formats
= RT5645_FORMATS
,
2599 .ops
= &rt5645_aif_dai_ops
,
2602 .name
= "rt5645-aif2",
2605 .stream_name
= "AIF2 Playback",
2608 .rates
= RT5645_STEREO_RATES
,
2609 .formats
= RT5645_FORMATS
,
2612 .stream_name
= "AIF2 Capture",
2615 .rates
= RT5645_STEREO_RATES
,
2616 .formats
= RT5645_FORMATS
,
2618 .ops
= &rt5645_aif_dai_ops
,
2622 static struct snd_soc_codec_driver soc_codec_dev_rt5645
= {
2623 .probe
= rt5645_probe
,
2624 .remove
= rt5645_remove
,
2625 .suspend
= rt5645_suspend
,
2626 .resume
= rt5645_resume
,
2627 .set_bias_level
= rt5645_set_bias_level
,
2628 .idle_bias_off
= true,
2629 .controls
= rt5645_snd_controls
,
2630 .num_controls
= ARRAY_SIZE(rt5645_snd_controls
),
2631 .dapm_widgets
= rt5645_dapm_widgets
,
2632 .num_dapm_widgets
= ARRAY_SIZE(rt5645_dapm_widgets
),
2633 .dapm_routes
= rt5645_dapm_routes
,
2634 .num_dapm_routes
= ARRAY_SIZE(rt5645_dapm_routes
),
2637 static const struct regmap_config rt5645_regmap
= {
2640 .use_single_rw
= true,
2641 .max_register
= RT5645_VENDOR_ID2
+ 1 + (ARRAY_SIZE(rt5645_ranges
) *
2643 .volatile_reg
= rt5645_volatile_register
,
2644 .readable_reg
= rt5645_readable_register
,
2646 .cache_type
= REGCACHE_RBTREE
,
2647 .reg_defaults
= rt5645_reg
,
2648 .num_reg_defaults
= ARRAY_SIZE(rt5645_reg
),
2649 .ranges
= rt5645_ranges
,
2650 .num_ranges
= ARRAY_SIZE(rt5645_ranges
),
2653 static const struct i2c_device_id rt5645_i2c_id
[] = {
2658 MODULE_DEVICE_TABLE(i2c
, rt5645_i2c_id
);
2661 static struct acpi_device_id rt5645_acpi_match
[] = {
2666 MODULE_DEVICE_TABLE(acpi
, rt5645_acpi_match
);
2669 static int rt5645_i2c_probe(struct i2c_client
*i2c
,
2670 const struct i2c_device_id
*id
)
2672 struct rt5645_platform_data
*pdata
= dev_get_platdata(&i2c
->dev
);
2673 struct rt5645_priv
*rt5645
;
2677 rt5645
= devm_kzalloc(&i2c
->dev
, sizeof(struct rt5645_priv
),
2683 i2c_set_clientdata(i2c
, rt5645
);
2686 rt5645
->pdata
= *pdata
;
2688 rt5645
->regmap
= devm_regmap_init_i2c(i2c
, &rt5645_regmap
);
2689 if (IS_ERR(rt5645
->regmap
)) {
2690 ret
= PTR_ERR(rt5645
->regmap
);
2691 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
2696 regmap_read(rt5645
->regmap
, RT5645_VENDOR_ID2
, &val
);
2699 case RT5645_DEVICE_ID
:
2700 rt5645
->codec_type
= CODEC_TYPE_RT5645
;
2702 case RT5650_DEVICE_ID
:
2703 rt5645
->codec_type
= CODEC_TYPE_RT5650
;
2707 "Device with ID register %x is not rt5645 or rt5650\n",
2712 regmap_write(rt5645
->regmap
, RT5645_RESET
, 0);
2714 ret
= regmap_register_patch(rt5645
->regmap
, init_list
,
2715 ARRAY_SIZE(init_list
));
2717 dev_warn(&i2c
->dev
, "Failed to apply regmap patch: %d\n", ret
);
2719 if (rt5645
->codec_type
== CODEC_TYPE_RT5650
) {
2720 ret
= regmap_register_patch(rt5645
->regmap
, rt5650_init_list
,
2721 ARRAY_SIZE(rt5650_init_list
));
2723 dev_warn(&i2c
->dev
, "Apply rt5650 patch failed: %d\n",
2727 if (rt5645
->pdata
.in2_diff
)
2728 regmap_update_bits(rt5645
->regmap
, RT5645_IN2_CTRL
,
2729 RT5645_IN_DF2
, RT5645_IN_DF2
);
2731 if (rt5645
->pdata
.dmic_en
) {
2732 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
2733 RT5645_GP2_PIN_MASK
, RT5645_GP2_PIN_DMIC1_SCL
);
2735 switch (rt5645
->pdata
.dmic1_data_pin
) {
2736 case RT5645_DMIC_DATA_IN2N
:
2737 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
2738 RT5645_DMIC_1_DP_MASK
, RT5645_DMIC_1_DP_IN2N
);
2741 case RT5645_DMIC_DATA_GPIO5
:
2742 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
2743 RT5645_DMIC_1_DP_MASK
, RT5645_DMIC_1_DP_GPIO5
);
2744 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
2745 RT5645_GP5_PIN_MASK
, RT5645_GP5_PIN_DMIC1_SDA
);
2748 case RT5645_DMIC_DATA_GPIO11
:
2749 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
2750 RT5645_DMIC_1_DP_MASK
, RT5645_DMIC_1_DP_GPIO11
);
2751 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
2752 RT5645_GP11_PIN_MASK
,
2753 RT5645_GP11_PIN_DMIC1_SDA
);
2760 switch (rt5645
->pdata
.dmic2_data_pin
) {
2761 case RT5645_DMIC_DATA_IN2P
:
2762 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
2763 RT5645_DMIC_2_DP_MASK
, RT5645_DMIC_2_DP_IN2P
);
2766 case RT5645_DMIC_DATA_GPIO6
:
2767 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
2768 RT5645_DMIC_2_DP_MASK
, RT5645_DMIC_2_DP_GPIO6
);
2769 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
2770 RT5645_GP6_PIN_MASK
, RT5645_GP6_PIN_DMIC2_SDA
);
2773 case RT5645_DMIC_DATA_GPIO10
:
2774 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
2775 RT5645_DMIC_2_DP_MASK
, RT5645_DMIC_2_DP_GPIO10
);
2776 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
2777 RT5645_GP10_PIN_MASK
,
2778 RT5645_GP10_PIN_DMIC2_SDA
);
2781 case RT5645_DMIC_DATA_GPIO12
:
2782 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
2783 RT5645_DMIC_2_DP_MASK
, RT5645_DMIC_2_DP_GPIO12
);
2784 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
2785 RT5645_GP12_PIN_MASK
,
2786 RT5645_GP12_PIN_DMIC2_SDA
);
2795 if (rt5645
->pdata
.en_jd_func
) {
2796 regmap_update_bits(rt5645
->regmap
, RT5645_GEN_CTRL3
,
2797 RT5645_IRQ_CLK_GATE_CTRL
| RT5645_MICINDET_MANU
,
2798 RT5645_IRQ_CLK_GATE_CTRL
| RT5645_MICINDET_MANU
);
2799 regmap_update_bits(rt5645
->regmap
, RT5645_IN1_CTRL1
,
2800 RT5645_CBJ_BST1_EN
, RT5645_CBJ_BST1_EN
);
2801 regmap_update_bits(rt5645
->regmap
, RT5645_JD_CTRL3
,
2802 RT5645_JD_CBJ_EN
| RT5645_JD_CBJ_POL
,
2803 RT5645_JD_CBJ_EN
| RT5645_JD_CBJ_POL
);
2804 regmap_update_bits(rt5645
->regmap
, RT5645_MICBIAS
,
2805 RT5645_IRQ_CLK_INT
, RT5645_IRQ_CLK_INT
);
2808 if (rt5645
->pdata
.jd_mode
) {
2809 regmap_update_bits(rt5645
->regmap
, RT5645_IRQ_CTRL2
,
2810 RT5645_IRQ_JD_1_1_EN
, RT5645_IRQ_JD_1_1_EN
);
2811 regmap_update_bits(rt5645
->regmap
, RT5645_GEN_CTRL3
,
2812 RT5645_JD_PSV_MODE
, RT5645_JD_PSV_MODE
);
2813 regmap_update_bits(rt5645
->regmap
, RT5645_HPO_MIXER
,
2814 RT5645_IRQ_PSV_MODE
, RT5645_IRQ_PSV_MODE
);
2815 regmap_update_bits(rt5645
->regmap
, RT5645_MICBIAS
,
2816 RT5645_MIC2_OVCD_EN
, RT5645_MIC2_OVCD_EN
);
2817 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
2818 RT5645_GP1_PIN_IRQ
, RT5645_GP1_PIN_IRQ
);
2819 switch (rt5645
->pdata
.jd_mode
) {
2821 regmap_update_bits(rt5645
->regmap
, RT5645_A_JD_CTRL1
,
2822 RT5645_JD1_MODE_MASK
,
2826 regmap_update_bits(rt5645
->regmap
, RT5645_A_JD_CTRL1
,
2827 RT5645_JD1_MODE_MASK
,
2831 regmap_update_bits(rt5645
->regmap
, RT5645_A_JD_CTRL1
,
2832 RT5645_JD1_MODE_MASK
,
2840 INIT_DELAYED_WORK(&rt5645
->jack_detect_work
, rt5645_jack_detect_work
);
2842 if (rt5645
->i2c
->irq
) {
2843 ret
= request_threaded_irq(rt5645
->i2c
->irq
, NULL
, rt5645_irq
,
2844 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
2845 | IRQF_ONESHOT
, "rt5645", rt5645
);
2847 dev_err(&i2c
->dev
, "Failed to reguest IRQ: %d\n", ret
);
2850 if (gpio_is_valid(rt5645
->pdata
.hp_det_gpio
)) {
2851 ret
= gpio_request(rt5645
->pdata
.hp_det_gpio
, "rt5645");
2853 dev_err(&i2c
->dev
, "Fail gpio_request hp_det_gpio\n");
2855 ret
= gpio_direction_input(rt5645
->pdata
.hp_det_gpio
);
2857 dev_err(&i2c
->dev
, "Fail gpio_direction hp_det_gpio\n");
2860 return snd_soc_register_codec(&i2c
->dev
, &soc_codec_dev_rt5645
,
2861 rt5645_dai
, ARRAY_SIZE(rt5645_dai
));
2864 static int rt5645_i2c_remove(struct i2c_client
*i2c
)
2866 struct rt5645_priv
*rt5645
= i2c_get_clientdata(i2c
);
2869 free_irq(i2c
->irq
, rt5645
);
2871 cancel_delayed_work_sync(&rt5645
->jack_detect_work
);
2873 if (gpio_is_valid(rt5645
->pdata
.hp_det_gpio
))
2874 gpio_free(rt5645
->pdata
.hp_det_gpio
);
2876 snd_soc_unregister_codec(&i2c
->dev
);
2881 static struct i2c_driver rt5645_i2c_driver
= {
2884 .owner
= THIS_MODULE
,
2885 .acpi_match_table
= ACPI_PTR(rt5645_acpi_match
),
2887 .probe
= rt5645_i2c_probe
,
2888 .remove
= rt5645_i2c_remove
,
2889 .id_table
= rt5645_i2c_id
,
2891 module_i2c_driver(rt5645_i2c_driver
);
2893 MODULE_DESCRIPTION("ASoC RT5645 driver");
2894 MODULE_AUTHOR("Bard Liao <bardliao@realtek.com>");
2895 MODULE_LICENSE("GPL v2");