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/gpio/consumer.h>
22 #include <linux/acpi.h>
23 #include <linux/dmi.h>
24 #include <linux/regulator/consumer.h>
25 #include <sound/core.h>
26 #include <sound/pcm.h>
27 #include <sound/pcm_params.h>
28 #include <sound/jack.h>
29 #include <sound/soc.h>
30 #include <sound/soc-dapm.h>
31 #include <sound/initval.h>
32 #include <sound/tlv.h>
37 #define RT5645_DEVICE_ID 0x6308
38 #define RT5650_DEVICE_ID 0x6419
40 #define RT5645_PR_RANGE_BASE (0xff + 1)
41 #define RT5645_PR_SPACING 0x100
43 #define RT5645_PR_BASE (RT5645_PR_RANGE_BASE + (0 * RT5645_PR_SPACING))
45 #define RT5645_HWEQ_NUM 57
47 static const struct regmap_range_cfg rt5645_ranges
[] = {
50 .range_min
= RT5645_PR_BASE
,
51 .range_max
= RT5645_PR_BASE
+ 0xf8,
52 .selector_reg
= RT5645_PRIV_INDEX
,
53 .selector_mask
= 0xff,
54 .selector_shift
= 0x0,
55 .window_start
= RT5645_PRIV_DATA
,
60 static const struct reg_sequence init_list
[] = {
61 {RT5645_PR_BASE
+ 0x3d, 0x3600},
62 {RT5645_PR_BASE
+ 0x1c, 0xfd20},
63 {RT5645_PR_BASE
+ 0x20, 0x611f},
64 {RT5645_PR_BASE
+ 0x21, 0x4040},
65 {RT5645_PR_BASE
+ 0x23, 0x0004},
68 static const struct reg_sequence rt5650_init_list
[] = {
72 static const struct reg_default rt5645_reg
[] = {
228 static const struct reg_default rt5650_reg
[] = {
385 struct rt5645_eq_param_s
{
390 static const char *const rt5645_supply_names
[] = {
396 struct snd_soc_codec
*codec
;
397 struct rt5645_platform_data pdata
;
398 struct regmap
*regmap
;
399 struct i2c_client
*i2c
;
400 struct gpio_desc
*gpiod_hp_det
;
401 struct snd_soc_jack
*hp_jack
;
402 struct snd_soc_jack
*mic_jack
;
403 struct snd_soc_jack
*btn_jack
;
404 struct delayed_work jack_detect_work
, rcclock_work
;
405 struct regulator_bulk_data supplies
[ARRAY_SIZE(rt5645_supply_names
)];
406 struct rt5645_eq_param_s
*eq_param
;
407 struct timer_list btn_check_timer
;
412 int lrck
[RT5645_AIFS
];
413 int bclk
[RT5645_AIFS
];
414 int master
[RT5645_AIFS
];
425 static int rt5645_reset(struct snd_soc_codec
*codec
)
427 return snd_soc_write(codec
, RT5645_RESET
, 0);
430 static bool rt5645_volatile_register(struct device
*dev
, unsigned int reg
)
434 for (i
= 0; i
< ARRAY_SIZE(rt5645_ranges
); i
++) {
435 if (reg
>= rt5645_ranges
[i
].range_min
&&
436 reg
<= rt5645_ranges
[i
].range_max
) {
443 case RT5645_PRIV_DATA
:
444 case RT5645_IN1_CTRL1
:
445 case RT5645_IN1_CTRL2
:
446 case RT5645_IN1_CTRL3
:
447 case RT5645_A_JD_CTRL1
:
448 case RT5645_ADC_EQ_CTRL1
:
449 case RT5645_EQ_CTRL1
:
450 case RT5645_ALC_CTRL_1
:
451 case RT5645_IRQ_CTRL2
:
452 case RT5645_IRQ_CTRL3
:
453 case RT5645_INT_IRQ_ST
:
455 case RT5650_4BTN_IL_CMD1
:
456 case RT5645_VENDOR_ID
:
457 case RT5645_VENDOR_ID1
:
458 case RT5645_VENDOR_ID2
:
465 static bool rt5645_readable_register(struct device
*dev
, unsigned int reg
)
469 for (i
= 0; i
< ARRAY_SIZE(rt5645_ranges
); i
++) {
470 if (reg
>= rt5645_ranges
[i
].range_min
&&
471 reg
<= rt5645_ranges
[i
].range_max
) {
481 case RT5645_IN1_CTRL1
:
482 case RT5645_IN1_CTRL2
:
483 case RT5645_IN1_CTRL3
:
484 case RT5645_IN2_CTRL
:
485 case RT5645_INL1_INR1_VOL
:
486 case RT5645_SPK_FUNC_LIM
:
487 case RT5645_ADJ_HPF_CTRL
:
488 case RT5645_DAC1_DIG_VOL
:
489 case RT5645_DAC2_DIG_VOL
:
490 case RT5645_DAC_CTRL
:
491 case RT5645_STO1_ADC_DIG_VOL
:
492 case RT5645_MONO_ADC_DIG_VOL
:
493 case RT5645_ADC_BST_VOL1
:
494 case RT5645_ADC_BST_VOL2
:
495 case RT5645_STO1_ADC_MIXER
:
496 case RT5645_MONO_ADC_MIXER
:
497 case RT5645_AD_DA_MIXER
:
498 case RT5645_STO_DAC_MIXER
:
499 case RT5645_MONO_DAC_MIXER
:
500 case RT5645_DIG_MIXER
:
501 case RT5650_A_DAC_SOUR
:
502 case RT5645_DIG_INF1_DATA
:
503 case RT5645_PDM_OUT_CTRL
:
504 case RT5645_REC_L1_MIXER
:
505 case RT5645_REC_L2_MIXER
:
506 case RT5645_REC_R1_MIXER
:
507 case RT5645_REC_R2_MIXER
:
508 case RT5645_HPMIXL_CTRL
:
509 case RT5645_HPOMIXL_CTRL
:
510 case RT5645_HPMIXR_CTRL
:
511 case RT5645_HPOMIXR_CTRL
:
512 case RT5645_HPO_MIXER
:
513 case RT5645_SPK_L_MIXER
:
514 case RT5645_SPK_R_MIXER
:
515 case RT5645_SPO_MIXER
:
516 case RT5645_SPO_CLSD_RATIO
:
517 case RT5645_OUT_L1_MIXER
:
518 case RT5645_OUT_R1_MIXER
:
519 case RT5645_OUT_L_GAIN1
:
520 case RT5645_OUT_L_GAIN2
:
521 case RT5645_OUT_R_GAIN1
:
522 case RT5645_OUT_R_GAIN2
:
523 case RT5645_LOUT_MIXER
:
524 case RT5645_HAPTIC_CTRL1
:
525 case RT5645_HAPTIC_CTRL2
:
526 case RT5645_HAPTIC_CTRL3
:
527 case RT5645_HAPTIC_CTRL4
:
528 case RT5645_HAPTIC_CTRL5
:
529 case RT5645_HAPTIC_CTRL6
:
530 case RT5645_HAPTIC_CTRL7
:
531 case RT5645_HAPTIC_CTRL8
:
532 case RT5645_HAPTIC_CTRL9
:
533 case RT5645_HAPTIC_CTRL10
:
534 case RT5645_PWR_DIG1
:
535 case RT5645_PWR_DIG2
:
536 case RT5645_PWR_ANLG1
:
537 case RT5645_PWR_ANLG2
:
538 case RT5645_PWR_MIXER
:
540 case RT5645_PRIV_INDEX
:
541 case RT5645_PRIV_DATA
:
542 case RT5645_I2S1_SDP
:
543 case RT5645_I2S2_SDP
:
544 case RT5645_ADDA_CLK1
:
545 case RT5645_ADDA_CLK2
:
546 case RT5645_DMIC_CTRL1
:
547 case RT5645_DMIC_CTRL2
:
548 case RT5645_TDM_CTRL_1
:
549 case RT5645_TDM_CTRL_2
:
550 case RT5645_TDM_CTRL_3
:
551 case RT5650_TDM_CTRL_4
:
553 case RT5645_PLL_CTRL1
:
554 case RT5645_PLL_CTRL2
:
559 case RT5645_DEPOP_M1
:
560 case RT5645_DEPOP_M2
:
561 case RT5645_DEPOP_M3
:
562 case RT5645_CHARGE_PUMP
:
564 case RT5645_A_JD_CTRL1
:
565 case RT5645_VAD_CTRL4
:
566 case RT5645_CLSD_OUT_CTRL
:
567 case RT5645_ADC_EQ_CTRL1
:
568 case RT5645_ADC_EQ_CTRL2
:
569 case RT5645_EQ_CTRL1
:
570 case RT5645_EQ_CTRL2
:
571 case RT5645_ALC_CTRL_1
:
572 case RT5645_ALC_CTRL_2
:
573 case RT5645_ALC_CTRL_3
:
574 case RT5645_ALC_CTRL_4
:
575 case RT5645_ALC_CTRL_5
:
577 case RT5645_IRQ_CTRL1
:
578 case RT5645_IRQ_CTRL2
:
579 case RT5645_IRQ_CTRL3
:
580 case RT5645_INT_IRQ_ST
:
581 case RT5645_GPIO_CTRL1
:
582 case RT5645_GPIO_CTRL2
:
583 case RT5645_GPIO_CTRL3
:
584 case RT5645_BASS_BACK
:
585 case RT5645_MP3_PLUS1
:
586 case RT5645_MP3_PLUS2
:
587 case RT5645_ADJ_HPF1
:
588 case RT5645_ADJ_HPF2
:
589 case RT5645_HP_CALIB_AMP_DET
:
595 case RT5650_4BTN_IL_CMD1
:
596 case RT5650_4BTN_IL_CMD2
:
597 case RT5645_DRC1_HL_CTRL1
:
598 case RT5645_DRC2_HL_CTRL1
:
599 case RT5645_ADC_MONO_HP_CTRL1
:
600 case RT5645_ADC_MONO_HP_CTRL2
:
601 case RT5645_DRC2_CTRL1
:
602 case RT5645_DRC2_CTRL2
:
603 case RT5645_DRC2_CTRL3
:
604 case RT5645_DRC2_CTRL4
:
605 case RT5645_DRC2_CTRL5
:
606 case RT5645_JD_CTRL3
:
607 case RT5645_JD_CTRL4
:
608 case RT5645_GEN_CTRL1
:
609 case RT5645_GEN_CTRL2
:
610 case RT5645_GEN_CTRL3
:
611 case RT5645_VENDOR_ID
:
612 case RT5645_VENDOR_ID1
:
613 case RT5645_VENDOR_ID2
:
620 static const DECLARE_TLV_DB_SCALE(out_vol_tlv
, -4650, 150, 0);
621 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv
, -6525, 75, 0);
622 static const DECLARE_TLV_DB_SCALE(in_vol_tlv
, -3450, 150, 0);
623 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv
, -1725, 75, 0);
624 static const DECLARE_TLV_DB_SCALE(adc_bst_tlv
, 0, 1200, 0);
626 /* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
627 static const DECLARE_TLV_DB_RANGE(bst_tlv
,
628 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
629 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
630 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
631 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
632 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
633 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
634 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0)
637 /* {-6, -4.5, -3, -1.5, 0, 0.82, 1.58, 2.28} dB */
638 static const DECLARE_TLV_DB_RANGE(spk_clsd_tlv
,
639 0, 4, TLV_DB_SCALE_ITEM(-600, 150, 0),
640 5, 5, TLV_DB_SCALE_ITEM(82, 0, 0),
641 6, 6, TLV_DB_SCALE_ITEM(158, 0, 0),
642 7, 7, TLV_DB_SCALE_ITEM(228, 0, 0)
645 static int rt5645_hweq_info(struct snd_kcontrol
*kcontrol
,
646 struct snd_ctl_elem_info
*uinfo
)
648 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
649 uinfo
->count
= RT5645_HWEQ_NUM
* sizeof(struct rt5645_eq_param_s
);
654 static int rt5645_hweq_get(struct snd_kcontrol
*kcontrol
,
655 struct snd_ctl_elem_value
*ucontrol
)
657 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
658 struct rt5645_priv
*rt5645
= snd_soc_component_get_drvdata(component
);
659 struct rt5645_eq_param_s
*eq_param
=
660 (struct rt5645_eq_param_s
*)ucontrol
->value
.bytes
.data
;
663 for (i
= 0; i
< RT5645_HWEQ_NUM
; i
++) {
664 eq_param
[i
].reg
= cpu_to_be16(rt5645
->eq_param
[i
].reg
);
665 eq_param
[i
].val
= cpu_to_be16(rt5645
->eq_param
[i
].val
);
671 static bool rt5645_validate_hweq(unsigned short reg
)
673 if ((reg
>= 0x1a4 && reg
<= 0x1cd) | (reg
>= 0x1e5 && reg
<= 0x1f8) |
674 (reg
== RT5645_EQ_CTRL2
))
680 static int rt5645_hweq_put(struct snd_kcontrol
*kcontrol
,
681 struct snd_ctl_elem_value
*ucontrol
)
683 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
684 struct rt5645_priv
*rt5645
= snd_soc_component_get_drvdata(component
);
685 struct rt5645_eq_param_s
*eq_param
=
686 (struct rt5645_eq_param_s
*)ucontrol
->value
.bytes
.data
;
689 for (i
= 0; i
< RT5645_HWEQ_NUM
; i
++) {
690 eq_param
[i
].reg
= be16_to_cpu(eq_param
[i
].reg
);
691 eq_param
[i
].val
= be16_to_cpu(eq_param
[i
].val
);
694 /* The final setting of the table should be RT5645_EQ_CTRL2 */
695 for (i
= RT5645_HWEQ_NUM
- 1; i
>= 0; i
--) {
696 if (eq_param
[i
].reg
== 0)
698 else if (eq_param
[i
].reg
!= RT5645_EQ_CTRL2
)
704 for (i
= 0; i
< RT5645_HWEQ_NUM
; i
++) {
705 if (!rt5645_validate_hweq(eq_param
[i
].reg
) &&
706 eq_param
[i
].reg
!= 0)
708 else if (eq_param
[i
].reg
== 0)
712 memcpy(rt5645
->eq_param
, eq_param
,
713 RT5645_HWEQ_NUM
* sizeof(struct rt5645_eq_param_s
));
718 #define RT5645_HWEQ(xname) \
719 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
720 .info = rt5645_hweq_info, \
721 .get = rt5645_hweq_get, \
722 .put = rt5645_hweq_put \
725 static int rt5645_spk_put_volsw(struct snd_kcontrol
*kcontrol
,
726 struct snd_ctl_elem_value
*ucontrol
)
728 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
729 struct rt5645_priv
*rt5645
= snd_soc_component_get_drvdata(component
);
732 regmap_update_bits(rt5645
->regmap
, RT5645_MICBIAS
,
733 RT5645_PWR_CLK25M_MASK
, RT5645_PWR_CLK25M_PU
);
735 ret
= snd_soc_put_volsw(kcontrol
, ucontrol
);
737 mod_delayed_work(system_power_efficient_wq
, &rt5645
->rcclock_work
,
738 msecs_to_jiffies(200));
743 static const struct snd_kcontrol_new rt5645_snd_controls
[] = {
744 /* Speaker Output Volume */
745 SOC_DOUBLE("Speaker Channel Switch", RT5645_SPK_VOL
,
746 RT5645_VOL_L_SFT
, RT5645_VOL_R_SFT
, 1, 1),
747 SOC_DOUBLE_EXT_TLV("Speaker Playback Volume", RT5645_SPK_VOL
,
748 RT5645_L_VOL_SFT
, RT5645_R_VOL_SFT
, 39, 1, snd_soc_get_volsw
,
749 rt5645_spk_put_volsw
, out_vol_tlv
),
751 /* ClassD modulator Speaker Gain Ratio */
752 SOC_SINGLE_TLV("Speaker ClassD Playback Volume", RT5645_SPO_CLSD_RATIO
,
753 RT5645_SPK_G_CLSD_SFT
, 7, 0, spk_clsd_tlv
),
755 /* Headphone Output Volume */
756 SOC_DOUBLE("Headphone Channel Switch", RT5645_HP_VOL
,
757 RT5645_VOL_L_SFT
, RT5645_VOL_R_SFT
, 1, 1),
758 SOC_DOUBLE_TLV("Headphone Playback Volume", RT5645_HP_VOL
,
759 RT5645_L_VOL_SFT
, RT5645_R_VOL_SFT
, 39, 1, out_vol_tlv
),
762 SOC_DOUBLE("OUT Playback Switch", RT5645_LOUT1
,
763 RT5645_L_MUTE_SFT
, RT5645_R_MUTE_SFT
, 1, 1),
764 SOC_DOUBLE("OUT Channel Switch", RT5645_LOUT1
,
765 RT5645_VOL_L_SFT
, RT5645_VOL_R_SFT
, 1, 1),
766 SOC_DOUBLE_TLV("OUT Playback Volume", RT5645_LOUT1
,
767 RT5645_L_VOL_SFT
, RT5645_R_VOL_SFT
, 39, 1, out_vol_tlv
),
769 /* DAC Digital Volume */
770 SOC_DOUBLE("DAC2 Playback Switch", RT5645_DAC_CTRL
,
771 RT5645_M_DAC_L2_VOL_SFT
, RT5645_M_DAC_R2_VOL_SFT
, 1, 1),
772 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5645_DAC1_DIG_VOL
,
773 RT5645_L_VOL_SFT
+ 1, RT5645_R_VOL_SFT
+ 1, 87, 0, dac_vol_tlv
),
774 SOC_DOUBLE_TLV("Mono DAC Playback Volume", RT5645_DAC2_DIG_VOL
,
775 RT5645_L_VOL_SFT
+ 1, RT5645_R_VOL_SFT
+ 1, 87, 0, dac_vol_tlv
),
777 /* IN1/IN2 Control */
778 SOC_SINGLE_TLV("IN1 Boost", RT5645_IN1_CTRL1
,
779 RT5645_BST_SFT1
, 12, 0, bst_tlv
),
780 SOC_SINGLE_TLV("IN2 Boost", RT5645_IN2_CTRL
,
781 RT5645_BST_SFT2
, 8, 0, bst_tlv
),
783 /* INL/INR Volume Control */
784 SOC_DOUBLE_TLV("IN Capture Volume", RT5645_INL1_INR1_VOL
,
785 RT5645_INL_VOL_SFT
, RT5645_INR_VOL_SFT
, 31, 1, in_vol_tlv
),
787 /* ADC Digital Volume Control */
788 SOC_DOUBLE("ADC Capture Switch", RT5645_STO1_ADC_DIG_VOL
,
789 RT5645_L_MUTE_SFT
, RT5645_R_MUTE_SFT
, 1, 1),
790 SOC_DOUBLE_TLV("ADC Capture Volume", RT5645_STO1_ADC_DIG_VOL
,
791 RT5645_L_VOL_SFT
+ 1, RT5645_R_VOL_SFT
+ 1, 63, 0, adc_vol_tlv
),
792 SOC_DOUBLE("Mono ADC Capture Switch", RT5645_MONO_ADC_DIG_VOL
,
793 RT5645_L_MUTE_SFT
, RT5645_R_MUTE_SFT
, 1, 1),
794 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5645_MONO_ADC_DIG_VOL
,
795 RT5645_L_VOL_SFT
+ 1, RT5645_R_VOL_SFT
+ 1, 63, 0, adc_vol_tlv
),
797 /* ADC Boost Volume Control */
798 SOC_DOUBLE_TLV("ADC Boost Capture Volume", RT5645_ADC_BST_VOL1
,
799 RT5645_STO1_ADC_L_BST_SFT
, RT5645_STO1_ADC_R_BST_SFT
, 3, 0,
801 SOC_DOUBLE_TLV("Mono ADC Boost Capture Volume", RT5645_ADC_BST_VOL2
,
802 RT5645_MONO_ADC_L_BST_SFT
, RT5645_MONO_ADC_R_BST_SFT
, 3, 0,
805 /* I2S2 function select */
806 SOC_SINGLE("I2S2 Func Switch", RT5645_GPIO_CTRL1
, RT5645_I2S2_SEL_SFT
,
808 RT5645_HWEQ("Speaker HWEQ"),
812 * set_dmic_clk - Set parameter of dmic.
815 * @kcontrol: The kcontrol of this widget.
819 static int set_dmic_clk(struct snd_soc_dapm_widget
*w
,
820 struct snd_kcontrol
*kcontrol
, int event
)
822 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
823 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
826 rate
= rt5645
->sysclk
/ rl6231_get_pre_div(rt5645
->regmap
,
827 RT5645_ADDA_CLK1
, RT5645_I2S_PD1_SFT
);
828 idx
= rl6231_calc_dmic_clk(rate
);
830 dev_err(codec
->dev
, "Failed to set DMIC clock\n");
832 snd_soc_update_bits(codec
, RT5645_DMIC_CTRL1
,
833 RT5645_DMIC_CLK_MASK
, idx
<< RT5645_DMIC_CLK_SFT
);
837 static int is_sys_clk_from_pll(struct snd_soc_dapm_widget
*source
,
838 struct snd_soc_dapm_widget
*sink
)
840 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(source
->dapm
);
843 val
= snd_soc_read(codec
, RT5645_GLB_CLK
);
844 val
&= RT5645_SCLK_SRC_MASK
;
845 if (val
== RT5645_SCLK_SRC_PLL1
)
851 static int is_using_asrc(struct snd_soc_dapm_widget
*source
,
852 struct snd_soc_dapm_widget
*sink
)
854 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(source
->dapm
);
855 unsigned int reg
, shift
, val
;
857 switch (source
->shift
) {
886 val
= (snd_soc_read(codec
, reg
) >> shift
) & 0xf;
899 static int rt5645_enable_hweq(struct snd_soc_codec
*codec
)
901 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
904 for (i
= 0; i
< RT5645_HWEQ_NUM
; i
++) {
905 if (rt5645_validate_hweq(rt5645
->eq_param
[i
].reg
))
906 regmap_write(rt5645
->regmap
, rt5645
->eq_param
[i
].reg
,
907 rt5645
->eq_param
[i
].val
);
916 * rt5645_sel_asrc_clk_src - select ASRC clock source for a set of filters
917 * @codec: SoC audio codec device.
918 * @filter_mask: mask of filters.
919 * @clk_src: clock source
921 * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5645 can
922 * only support standard 32fs or 64fs i2s format, ASRC should be enabled to
923 * support special i2s clock format such as Intel's 100fs(100 * sampling rate).
924 * ASRC function will track i2s clock and generate a corresponding system clock
925 * for codec. This function provides an API to select the clock source for a
926 * set of filters specified by the mask. And the codec driver will turn on ASRC
927 * for these filters if ASRC is selected as their clock source.
929 int rt5645_sel_asrc_clk_src(struct snd_soc_codec
*codec
,
930 unsigned int filter_mask
, unsigned int clk_src
)
932 unsigned int asrc2_mask
= 0;
933 unsigned int asrc2_value
= 0;
934 unsigned int asrc3_mask
= 0;
935 unsigned int asrc3_value
= 0;
938 case RT5645_CLK_SEL_SYS
:
939 case RT5645_CLK_SEL_I2S1_ASRC
:
940 case RT5645_CLK_SEL_I2S2_ASRC
:
941 case RT5645_CLK_SEL_SYS2
:
948 if (filter_mask
& RT5645_DA_STEREO_FILTER
) {
949 asrc2_mask
|= RT5645_DA_STO_CLK_SEL_MASK
;
950 asrc2_value
= (asrc2_value
& ~RT5645_DA_STO_CLK_SEL_MASK
)
951 | (clk_src
<< RT5645_DA_STO_CLK_SEL_SFT
);
954 if (filter_mask
& RT5645_DA_MONO_L_FILTER
) {
955 asrc2_mask
|= RT5645_DA_MONOL_CLK_SEL_MASK
;
956 asrc2_value
= (asrc2_value
& ~RT5645_DA_MONOL_CLK_SEL_MASK
)
957 | (clk_src
<< RT5645_DA_MONOL_CLK_SEL_SFT
);
960 if (filter_mask
& RT5645_DA_MONO_R_FILTER
) {
961 asrc2_mask
|= RT5645_DA_MONOR_CLK_SEL_MASK
;
962 asrc2_value
= (asrc2_value
& ~RT5645_DA_MONOR_CLK_SEL_MASK
)
963 | (clk_src
<< RT5645_DA_MONOR_CLK_SEL_SFT
);
966 if (filter_mask
& RT5645_AD_STEREO_FILTER
) {
967 asrc2_mask
|= RT5645_AD_STO1_CLK_SEL_MASK
;
968 asrc2_value
= (asrc2_value
& ~RT5645_AD_STO1_CLK_SEL_MASK
)
969 | (clk_src
<< RT5645_AD_STO1_CLK_SEL_SFT
);
972 if (filter_mask
& RT5645_AD_MONO_L_FILTER
) {
973 asrc3_mask
|= RT5645_AD_MONOL_CLK_SEL_MASK
;
974 asrc3_value
= (asrc3_value
& ~RT5645_AD_MONOL_CLK_SEL_MASK
)
975 | (clk_src
<< RT5645_AD_MONOL_CLK_SEL_SFT
);
978 if (filter_mask
& RT5645_AD_MONO_R_FILTER
) {
979 asrc3_mask
|= RT5645_AD_MONOR_CLK_SEL_MASK
;
980 asrc3_value
= (asrc3_value
& ~RT5645_AD_MONOR_CLK_SEL_MASK
)
981 | (clk_src
<< RT5645_AD_MONOR_CLK_SEL_SFT
);
985 snd_soc_update_bits(codec
, RT5645_ASRC_2
,
986 asrc2_mask
, asrc2_value
);
989 snd_soc_update_bits(codec
, RT5645_ASRC_3
,
990 asrc3_mask
, asrc3_value
);
994 EXPORT_SYMBOL_GPL(rt5645_sel_asrc_clk_src
);
997 static const struct snd_kcontrol_new rt5645_sto1_adc_l_mix
[] = {
998 SOC_DAPM_SINGLE("ADC1 Switch", RT5645_STO1_ADC_MIXER
,
999 RT5645_M_ADC_L1_SFT
, 1, 1),
1000 SOC_DAPM_SINGLE("ADC2 Switch", RT5645_STO1_ADC_MIXER
,
1001 RT5645_M_ADC_L2_SFT
, 1, 1),
1004 static const struct snd_kcontrol_new rt5645_sto1_adc_r_mix
[] = {
1005 SOC_DAPM_SINGLE("ADC1 Switch", RT5645_STO1_ADC_MIXER
,
1006 RT5645_M_ADC_R1_SFT
, 1, 1),
1007 SOC_DAPM_SINGLE("ADC2 Switch", RT5645_STO1_ADC_MIXER
,
1008 RT5645_M_ADC_R2_SFT
, 1, 1),
1011 static const struct snd_kcontrol_new rt5645_mono_adc_l_mix
[] = {
1012 SOC_DAPM_SINGLE("ADC1 Switch", RT5645_MONO_ADC_MIXER
,
1013 RT5645_M_MONO_ADC_L1_SFT
, 1, 1),
1014 SOC_DAPM_SINGLE("ADC2 Switch", RT5645_MONO_ADC_MIXER
,
1015 RT5645_M_MONO_ADC_L2_SFT
, 1, 1),
1018 static const struct snd_kcontrol_new rt5645_mono_adc_r_mix
[] = {
1019 SOC_DAPM_SINGLE("ADC1 Switch", RT5645_MONO_ADC_MIXER
,
1020 RT5645_M_MONO_ADC_R1_SFT
, 1, 1),
1021 SOC_DAPM_SINGLE("ADC2 Switch", RT5645_MONO_ADC_MIXER
,
1022 RT5645_M_MONO_ADC_R2_SFT
, 1, 1),
1025 static const struct snd_kcontrol_new rt5645_dac_l_mix
[] = {
1026 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5645_AD_DA_MIXER
,
1027 RT5645_M_ADCMIX_L_SFT
, 1, 1),
1028 SOC_DAPM_SINGLE_AUTODISABLE("DAC1 Switch", RT5645_AD_DA_MIXER
,
1029 RT5645_M_DAC1_L_SFT
, 1, 1),
1032 static const struct snd_kcontrol_new rt5645_dac_r_mix
[] = {
1033 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5645_AD_DA_MIXER
,
1034 RT5645_M_ADCMIX_R_SFT
, 1, 1),
1035 SOC_DAPM_SINGLE_AUTODISABLE("DAC1 Switch", RT5645_AD_DA_MIXER
,
1036 RT5645_M_DAC1_R_SFT
, 1, 1),
1039 static const struct snd_kcontrol_new rt5645_sto_dac_l_mix
[] = {
1040 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_STO_DAC_MIXER
,
1041 RT5645_M_DAC_L1_SFT
, 1, 1),
1042 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_STO_DAC_MIXER
,
1043 RT5645_M_DAC_L2_SFT
, 1, 1),
1044 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_STO_DAC_MIXER
,
1045 RT5645_M_DAC_R1_STO_L_SFT
, 1, 1),
1048 static const struct snd_kcontrol_new rt5645_sto_dac_r_mix
[] = {
1049 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_STO_DAC_MIXER
,
1050 RT5645_M_DAC_R1_SFT
, 1, 1),
1051 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_STO_DAC_MIXER
,
1052 RT5645_M_DAC_R2_SFT
, 1, 1),
1053 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_STO_DAC_MIXER
,
1054 RT5645_M_DAC_L1_STO_R_SFT
, 1, 1),
1057 static const struct snd_kcontrol_new rt5645_mono_dac_l_mix
[] = {
1058 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_MONO_DAC_MIXER
,
1059 RT5645_M_DAC_L1_MONO_L_SFT
, 1, 1),
1060 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_MONO_DAC_MIXER
,
1061 RT5645_M_DAC_L2_MONO_L_SFT
, 1, 1),
1062 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_MONO_DAC_MIXER
,
1063 RT5645_M_DAC_R2_MONO_L_SFT
, 1, 1),
1066 static const struct snd_kcontrol_new rt5645_mono_dac_r_mix
[] = {
1067 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_MONO_DAC_MIXER
,
1068 RT5645_M_DAC_R1_MONO_R_SFT
, 1, 1),
1069 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_MONO_DAC_MIXER
,
1070 RT5645_M_DAC_R2_MONO_R_SFT
, 1, 1),
1071 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_MONO_DAC_MIXER
,
1072 RT5645_M_DAC_L2_MONO_R_SFT
, 1, 1),
1075 static const struct snd_kcontrol_new rt5645_dig_l_mix
[] = {
1076 SOC_DAPM_SINGLE("Sto DAC Mix L Switch", RT5645_DIG_MIXER
,
1077 RT5645_M_STO_L_DAC_L_SFT
, 1, 1),
1078 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_DIG_MIXER
,
1079 RT5645_M_DAC_L2_DAC_L_SFT
, 1, 1),
1080 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_DIG_MIXER
,
1081 RT5645_M_DAC_R2_DAC_L_SFT
, 1, 1),
1084 static const struct snd_kcontrol_new rt5645_dig_r_mix
[] = {
1085 SOC_DAPM_SINGLE("Sto DAC Mix R Switch", RT5645_DIG_MIXER
,
1086 RT5645_M_STO_R_DAC_R_SFT
, 1, 1),
1087 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_DIG_MIXER
,
1088 RT5645_M_DAC_R2_DAC_R_SFT
, 1, 1),
1089 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_DIG_MIXER
,
1090 RT5645_M_DAC_L2_DAC_R_SFT
, 1, 1),
1093 /* Analog Input Mixer */
1094 static const struct snd_kcontrol_new rt5645_rec_l_mix
[] = {
1095 SOC_DAPM_SINGLE("HPOL Switch", RT5645_REC_L2_MIXER
,
1096 RT5645_M_HP_L_RM_L_SFT
, 1, 1),
1097 SOC_DAPM_SINGLE("INL Switch", RT5645_REC_L2_MIXER
,
1098 RT5645_M_IN_L_RM_L_SFT
, 1, 1),
1099 SOC_DAPM_SINGLE("BST2 Switch", RT5645_REC_L2_MIXER
,
1100 RT5645_M_BST2_RM_L_SFT
, 1, 1),
1101 SOC_DAPM_SINGLE("BST1 Switch", RT5645_REC_L2_MIXER
,
1102 RT5645_M_BST1_RM_L_SFT
, 1, 1),
1103 SOC_DAPM_SINGLE("OUT MIXL Switch", RT5645_REC_L2_MIXER
,
1104 RT5645_M_OM_L_RM_L_SFT
, 1, 1),
1107 static const struct snd_kcontrol_new rt5645_rec_r_mix
[] = {
1108 SOC_DAPM_SINGLE("HPOR Switch", RT5645_REC_R2_MIXER
,
1109 RT5645_M_HP_R_RM_R_SFT
, 1, 1),
1110 SOC_DAPM_SINGLE("INR Switch", RT5645_REC_R2_MIXER
,
1111 RT5645_M_IN_R_RM_R_SFT
, 1, 1),
1112 SOC_DAPM_SINGLE("BST2 Switch", RT5645_REC_R2_MIXER
,
1113 RT5645_M_BST2_RM_R_SFT
, 1, 1),
1114 SOC_DAPM_SINGLE("BST1 Switch", RT5645_REC_R2_MIXER
,
1115 RT5645_M_BST1_RM_R_SFT
, 1, 1),
1116 SOC_DAPM_SINGLE("OUT MIXR Switch", RT5645_REC_R2_MIXER
,
1117 RT5645_M_OM_R_RM_R_SFT
, 1, 1),
1120 static const struct snd_kcontrol_new rt5645_spk_l_mix
[] = {
1121 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_SPK_L_MIXER
,
1122 RT5645_M_DAC_L1_SM_L_SFT
, 1, 1),
1123 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_SPK_L_MIXER
,
1124 RT5645_M_DAC_L2_SM_L_SFT
, 1, 1),
1125 SOC_DAPM_SINGLE("INL Switch", RT5645_SPK_L_MIXER
,
1126 RT5645_M_IN_L_SM_L_SFT
, 1, 1),
1127 SOC_DAPM_SINGLE("BST1 Switch", RT5645_SPK_L_MIXER
,
1128 RT5645_M_BST1_L_SM_L_SFT
, 1, 1),
1131 static const struct snd_kcontrol_new rt5645_spk_r_mix
[] = {
1132 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_SPK_R_MIXER
,
1133 RT5645_M_DAC_R1_SM_R_SFT
, 1, 1),
1134 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_SPK_R_MIXER
,
1135 RT5645_M_DAC_R2_SM_R_SFT
, 1, 1),
1136 SOC_DAPM_SINGLE("INR Switch", RT5645_SPK_R_MIXER
,
1137 RT5645_M_IN_R_SM_R_SFT
, 1, 1),
1138 SOC_DAPM_SINGLE("BST2 Switch", RT5645_SPK_R_MIXER
,
1139 RT5645_M_BST2_R_SM_R_SFT
, 1, 1),
1142 static const struct snd_kcontrol_new rt5645_out_l_mix
[] = {
1143 SOC_DAPM_SINGLE("BST1 Switch", RT5645_OUT_L1_MIXER
,
1144 RT5645_M_BST1_OM_L_SFT
, 1, 1),
1145 SOC_DAPM_SINGLE("INL Switch", RT5645_OUT_L1_MIXER
,
1146 RT5645_M_IN_L_OM_L_SFT
, 1, 1),
1147 SOC_DAPM_SINGLE("DAC L2 Switch", RT5645_OUT_L1_MIXER
,
1148 RT5645_M_DAC_L2_OM_L_SFT
, 1, 1),
1149 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_OUT_L1_MIXER
,
1150 RT5645_M_DAC_L1_OM_L_SFT
, 1, 1),
1153 static const struct snd_kcontrol_new rt5645_out_r_mix
[] = {
1154 SOC_DAPM_SINGLE("BST2 Switch", RT5645_OUT_R1_MIXER
,
1155 RT5645_M_BST2_OM_R_SFT
, 1, 1),
1156 SOC_DAPM_SINGLE("INR Switch", RT5645_OUT_R1_MIXER
,
1157 RT5645_M_IN_R_OM_R_SFT
, 1, 1),
1158 SOC_DAPM_SINGLE("DAC R2 Switch", RT5645_OUT_R1_MIXER
,
1159 RT5645_M_DAC_R2_OM_R_SFT
, 1, 1),
1160 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_OUT_R1_MIXER
,
1161 RT5645_M_DAC_R1_OM_R_SFT
, 1, 1),
1164 static const struct snd_kcontrol_new rt5645_spo_l_mix
[] = {
1165 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_SPO_MIXER
,
1166 RT5645_M_DAC_R1_SPM_L_SFT
, 1, 1),
1167 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_SPO_MIXER
,
1168 RT5645_M_DAC_L1_SPM_L_SFT
, 1, 1),
1169 SOC_DAPM_SINGLE("SPKVOL R Switch", RT5645_SPO_MIXER
,
1170 RT5645_M_SV_R_SPM_L_SFT
, 1, 1),
1171 SOC_DAPM_SINGLE("SPKVOL L Switch", RT5645_SPO_MIXER
,
1172 RT5645_M_SV_L_SPM_L_SFT
, 1, 1),
1175 static const struct snd_kcontrol_new rt5645_spo_r_mix
[] = {
1176 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_SPO_MIXER
,
1177 RT5645_M_DAC_R1_SPM_R_SFT
, 1, 1),
1178 SOC_DAPM_SINGLE("SPKVOL R Switch", RT5645_SPO_MIXER
,
1179 RT5645_M_SV_R_SPM_R_SFT
, 1, 1),
1182 static const struct snd_kcontrol_new rt5645_hpo_mix
[] = {
1183 SOC_DAPM_SINGLE("DAC1 Switch", RT5645_HPO_MIXER
,
1184 RT5645_M_DAC1_HM_SFT
, 1, 1),
1185 SOC_DAPM_SINGLE("HPVOL Switch", RT5645_HPO_MIXER
,
1186 RT5645_M_HPVOL_HM_SFT
, 1, 1),
1189 static const struct snd_kcontrol_new rt5645_hpvoll_mix
[] = {
1190 SOC_DAPM_SINGLE("DAC1 Switch", RT5645_HPOMIXL_CTRL
,
1191 RT5645_M_DAC1_HV_SFT
, 1, 1),
1192 SOC_DAPM_SINGLE("DAC2 Switch", RT5645_HPOMIXL_CTRL
,
1193 RT5645_M_DAC2_HV_SFT
, 1, 1),
1194 SOC_DAPM_SINGLE("INL Switch", RT5645_HPOMIXL_CTRL
,
1195 RT5645_M_IN_HV_SFT
, 1, 1),
1196 SOC_DAPM_SINGLE("BST1 Switch", RT5645_HPOMIXL_CTRL
,
1197 RT5645_M_BST1_HV_SFT
, 1, 1),
1200 static const struct snd_kcontrol_new rt5645_hpvolr_mix
[] = {
1201 SOC_DAPM_SINGLE("DAC1 Switch", RT5645_HPOMIXR_CTRL
,
1202 RT5645_M_DAC1_HV_SFT
, 1, 1),
1203 SOC_DAPM_SINGLE("DAC2 Switch", RT5645_HPOMIXR_CTRL
,
1204 RT5645_M_DAC2_HV_SFT
, 1, 1),
1205 SOC_DAPM_SINGLE("INR Switch", RT5645_HPOMIXR_CTRL
,
1206 RT5645_M_IN_HV_SFT
, 1, 1),
1207 SOC_DAPM_SINGLE("BST2 Switch", RT5645_HPOMIXR_CTRL
,
1208 RT5645_M_BST2_HV_SFT
, 1, 1),
1211 static const struct snd_kcontrol_new rt5645_lout_mix
[] = {
1212 SOC_DAPM_SINGLE("DAC L1 Switch", RT5645_LOUT_MIXER
,
1213 RT5645_M_DAC_L1_LM_SFT
, 1, 1),
1214 SOC_DAPM_SINGLE("DAC R1 Switch", RT5645_LOUT_MIXER
,
1215 RT5645_M_DAC_R1_LM_SFT
, 1, 1),
1216 SOC_DAPM_SINGLE("OUTMIX L Switch", RT5645_LOUT_MIXER
,
1217 RT5645_M_OV_L_LM_SFT
, 1, 1),
1218 SOC_DAPM_SINGLE("OUTMIX R Switch", RT5645_LOUT_MIXER
,
1219 RT5645_M_OV_R_LM_SFT
, 1, 1),
1222 /*DAC1 L/R source*/ /* MX-29 [9:8] [11:10] */
1223 static const char * const rt5645_dac1_src
[] = {
1224 "IF1 DAC", "IF2 DAC", "IF3 DAC"
1227 static SOC_ENUM_SINGLE_DECL(
1228 rt5645_dac1l_enum
, RT5645_AD_DA_MIXER
,
1229 RT5645_DAC1_L_SEL_SFT
, rt5645_dac1_src
);
1231 static const struct snd_kcontrol_new rt5645_dac1l_mux
=
1232 SOC_DAPM_ENUM("DAC1 L source", rt5645_dac1l_enum
);
1234 static SOC_ENUM_SINGLE_DECL(
1235 rt5645_dac1r_enum
, RT5645_AD_DA_MIXER
,
1236 RT5645_DAC1_R_SEL_SFT
, rt5645_dac1_src
);
1238 static const struct snd_kcontrol_new rt5645_dac1r_mux
=
1239 SOC_DAPM_ENUM("DAC1 R source", rt5645_dac1r_enum
);
1241 /*DAC2 L/R source*/ /* MX-1B [6:4] [2:0] */
1242 static const char * const rt5645_dac12_src
[] = {
1243 "IF1 DAC", "IF2 DAC", "IF3 DAC", "Mono ADC", "VAD_ADC"
1246 static SOC_ENUM_SINGLE_DECL(
1247 rt5645_dac2l_enum
, RT5645_DAC_CTRL
,
1248 RT5645_DAC2_L_SEL_SFT
, rt5645_dac12_src
);
1250 static const struct snd_kcontrol_new rt5645_dac_l2_mux
=
1251 SOC_DAPM_ENUM("DAC2 L source", rt5645_dac2l_enum
);
1253 static const char * const rt5645_dacr2_src
[] = {
1254 "IF1 DAC", "IF2 DAC", "IF3 DAC", "Mono ADC", "Haptic"
1257 static SOC_ENUM_SINGLE_DECL(
1258 rt5645_dac2r_enum
, RT5645_DAC_CTRL
,
1259 RT5645_DAC2_R_SEL_SFT
, rt5645_dacr2_src
);
1261 static const struct snd_kcontrol_new rt5645_dac_r2_mux
=
1262 SOC_DAPM_ENUM("DAC2 R source", rt5645_dac2r_enum
);
1266 static const char * const rt5645_inl_src
[] = {
1270 static SOC_ENUM_SINGLE_DECL(
1271 rt5645_inl_enum
, RT5645_INL1_INR1_VOL
,
1272 RT5645_INL_SEL_SFT
, rt5645_inl_src
);
1274 static const struct snd_kcontrol_new rt5645_inl_mux
=
1275 SOC_DAPM_ENUM("INL source", rt5645_inl_enum
);
1277 static const char * const rt5645_inr_src
[] = {
1281 static SOC_ENUM_SINGLE_DECL(
1282 rt5645_inr_enum
, RT5645_INL1_INR1_VOL
,
1283 RT5645_INR_SEL_SFT
, rt5645_inr_src
);
1285 static const struct snd_kcontrol_new rt5645_inr_mux
=
1286 SOC_DAPM_ENUM("INR source", rt5645_inr_enum
);
1288 /* Stereo1 ADC source */
1290 static const char * const rt5645_stereo_adc1_src
[] = {
1294 static SOC_ENUM_SINGLE_DECL(
1295 rt5645_stereo1_adc1_enum
, RT5645_STO1_ADC_MIXER
,
1296 RT5645_ADC_1_SRC_SFT
, rt5645_stereo_adc1_src
);
1298 static const struct snd_kcontrol_new rt5645_sto_adc1_mux
=
1299 SOC_DAPM_ENUM("Stereo1 ADC1 Mux", rt5645_stereo1_adc1_enum
);
1302 static const char * const rt5645_stereo_adc2_src
[] = {
1306 static SOC_ENUM_SINGLE_DECL(
1307 rt5645_stereo1_adc2_enum
, RT5645_STO1_ADC_MIXER
,
1308 RT5645_ADC_2_SRC_SFT
, rt5645_stereo_adc2_src
);
1310 static const struct snd_kcontrol_new rt5645_sto_adc2_mux
=
1311 SOC_DAPM_ENUM("Stereo1 ADC2 Mux", rt5645_stereo1_adc2_enum
);
1314 static const char * const rt5645_stereo_dmic_src
[] = {
1318 static SOC_ENUM_SINGLE_DECL(
1319 rt5645_stereo1_dmic_enum
, RT5645_STO1_ADC_MIXER
,
1320 RT5645_DMIC_SRC_SFT
, rt5645_stereo_dmic_src
);
1322 static const struct snd_kcontrol_new rt5645_sto1_dmic_mux
=
1323 SOC_DAPM_ENUM("Stereo1 DMIC source", rt5645_stereo1_dmic_enum
);
1325 /* Mono ADC source */
1327 static const char * const rt5645_mono_adc_l1_src
[] = {
1328 "Mono DAC MIXL", "ADC"
1331 static SOC_ENUM_SINGLE_DECL(
1332 rt5645_mono_adc_l1_enum
, RT5645_MONO_ADC_MIXER
,
1333 RT5645_MONO_ADC_L1_SRC_SFT
, rt5645_mono_adc_l1_src
);
1335 static const struct snd_kcontrol_new rt5645_mono_adc_l1_mux
=
1336 SOC_DAPM_ENUM("Mono ADC1 left source", rt5645_mono_adc_l1_enum
);
1338 static const char * const rt5645_mono_adc_l2_src
[] = {
1339 "Mono DAC MIXL", "DMIC"
1342 static SOC_ENUM_SINGLE_DECL(
1343 rt5645_mono_adc_l2_enum
, RT5645_MONO_ADC_MIXER
,
1344 RT5645_MONO_ADC_L2_SRC_SFT
, rt5645_mono_adc_l2_src
);
1346 static const struct snd_kcontrol_new rt5645_mono_adc_l2_mux
=
1347 SOC_DAPM_ENUM("Mono ADC2 left source", rt5645_mono_adc_l2_enum
);
1350 static const char * const rt5645_mono_dmic_src
[] = {
1354 static SOC_ENUM_SINGLE_DECL(
1355 rt5645_mono_dmic_l_enum
, RT5645_MONO_ADC_MIXER
,
1356 RT5645_MONO_DMIC_L_SRC_SFT
, rt5645_mono_dmic_src
);
1358 static const struct snd_kcontrol_new rt5645_mono_dmic_l_mux
=
1359 SOC_DAPM_ENUM("Mono DMIC left source", rt5645_mono_dmic_l_enum
);
1361 static SOC_ENUM_SINGLE_DECL(
1362 rt5645_mono_dmic_r_enum
, RT5645_MONO_ADC_MIXER
,
1363 RT5645_MONO_DMIC_R_SRC_SFT
, rt5645_mono_dmic_src
);
1365 static const struct snd_kcontrol_new rt5645_mono_dmic_r_mux
=
1366 SOC_DAPM_ENUM("Mono DMIC Right source", rt5645_mono_dmic_r_enum
);
1368 static const char * const rt5645_mono_adc_r1_src
[] = {
1369 "Mono DAC MIXR", "ADC"
1372 static SOC_ENUM_SINGLE_DECL(
1373 rt5645_mono_adc_r1_enum
, RT5645_MONO_ADC_MIXER
,
1374 RT5645_MONO_ADC_R1_SRC_SFT
, rt5645_mono_adc_r1_src
);
1376 static const struct snd_kcontrol_new rt5645_mono_adc_r1_mux
=
1377 SOC_DAPM_ENUM("Mono ADC1 right source", rt5645_mono_adc_r1_enum
);
1379 static const char * const rt5645_mono_adc_r2_src
[] = {
1380 "Mono DAC MIXR", "DMIC"
1383 static SOC_ENUM_SINGLE_DECL(
1384 rt5645_mono_adc_r2_enum
, RT5645_MONO_ADC_MIXER
,
1385 RT5645_MONO_ADC_R2_SRC_SFT
, rt5645_mono_adc_r2_src
);
1387 static const struct snd_kcontrol_new rt5645_mono_adc_r2_mux
=
1388 SOC_DAPM_ENUM("Mono ADC2 right source", rt5645_mono_adc_r2_enum
);
1391 static const char * const rt5645_if1_adc_in_src
[] = {
1392 "IF_ADC1/IF_ADC2/VAD_ADC", "IF_ADC2/IF_ADC1/VAD_ADC",
1393 "VAD_ADC/IF_ADC1/IF_ADC2", "VAD_ADC/IF_ADC2/IF_ADC1"
1396 static SOC_ENUM_SINGLE_DECL(
1397 rt5645_if1_adc_in_enum
, RT5645_TDM_CTRL_1
,
1398 RT5645_IF1_ADC_IN_SFT
, rt5645_if1_adc_in_src
);
1400 static const struct snd_kcontrol_new rt5645_if1_adc_in_mux
=
1401 SOC_DAPM_ENUM("IF1 ADC IN source", rt5645_if1_adc_in_enum
);
1404 static const char * const rt5650_if1_adc_in_src
[] = {
1405 "IF_ADC1/IF_ADC2/DAC_REF/Null",
1406 "IF_ADC1/IF_ADC2/Null/DAC_REF",
1407 "IF_ADC1/DAC_REF/IF_ADC2/Null",
1408 "IF_ADC1/DAC_REF/Null/IF_ADC2",
1409 "IF_ADC1/Null/DAC_REF/IF_ADC2",
1410 "IF_ADC1/Null/IF_ADC2/DAC_REF",
1412 "IF_ADC2/IF_ADC1/DAC_REF/Null",
1413 "IF_ADC2/IF_ADC1/Null/DAC_REF",
1414 "IF_ADC2/DAC_REF/IF_ADC1/Null",
1415 "IF_ADC2/DAC_REF/Null/IF_ADC1",
1416 "IF_ADC2/Null/DAC_REF/IF_ADC1",
1417 "IF_ADC2/Null/IF_ADC1/DAC_REF",
1419 "DAC_REF/IF_ADC1/IF_ADC2/Null",
1420 "DAC_REF/IF_ADC1/Null/IF_ADC2",
1421 "DAC_REF/IF_ADC2/IF_ADC1/Null",
1422 "DAC_REF/IF_ADC2/Null/IF_ADC1",
1423 "DAC_REF/Null/IF_ADC1/IF_ADC2",
1424 "DAC_REF/Null/IF_ADC2/IF_ADC1",
1426 "Null/IF_ADC1/IF_ADC2/DAC_REF",
1427 "Null/IF_ADC1/DAC_REF/IF_ADC2",
1428 "Null/IF_ADC2/IF_ADC1/DAC_REF",
1429 "Null/IF_ADC2/DAC_REF/IF_ADC1",
1430 "Null/DAC_REF/IF_ADC1/IF_ADC2",
1431 "Null/DAC_REF/IF_ADC2/IF_ADC1",
1434 static SOC_ENUM_SINGLE_DECL(
1435 rt5650_if1_adc_in_enum
, RT5645_TDM_CTRL_2
,
1436 0, rt5650_if1_adc_in_src
);
1438 static const struct snd_kcontrol_new rt5650_if1_adc_in_mux
=
1439 SOC_DAPM_ENUM("IF1 ADC IN source", rt5650_if1_adc_in_enum
);
1441 /* MX-78 [15:14][13:12][11:10] */
1442 static const char * const rt5645_tdm_adc_swap_select
[] = {
1443 "L/R", "R/L", "L/L", "R/R"
1446 static SOC_ENUM_SINGLE_DECL(rt5650_tdm_adc_slot0_1_enum
,
1447 RT5645_TDM_CTRL_2
, 14, rt5645_tdm_adc_swap_select
);
1449 static const struct snd_kcontrol_new rt5650_if1_adc1_in_mux
=
1450 SOC_DAPM_ENUM("IF1 ADC1 IN source", rt5650_tdm_adc_slot0_1_enum
);
1452 static SOC_ENUM_SINGLE_DECL(rt5650_tdm_adc_slot2_3_enum
,
1453 RT5645_TDM_CTRL_2
, 12, rt5645_tdm_adc_swap_select
);
1455 static const struct snd_kcontrol_new rt5650_if1_adc2_in_mux
=
1456 SOC_DAPM_ENUM("IF1 ADC2 IN source", rt5650_tdm_adc_slot2_3_enum
);
1458 static SOC_ENUM_SINGLE_DECL(rt5650_tdm_adc_slot4_5_enum
,
1459 RT5645_TDM_CTRL_2
, 10, rt5645_tdm_adc_swap_select
);
1461 static const struct snd_kcontrol_new rt5650_if1_adc3_in_mux
=
1462 SOC_DAPM_ENUM("IF1 ADC3 IN source", rt5650_tdm_adc_slot4_5_enum
);
1464 /* MX-77 [7:6][5:4][3:2] */
1465 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot0_1_enum
,
1466 RT5645_TDM_CTRL_1
, 6, rt5645_tdm_adc_swap_select
);
1468 static const struct snd_kcontrol_new rt5645_if1_adc1_in_mux
=
1469 SOC_DAPM_ENUM("IF1 ADC1 IN source", rt5645_tdm_adc_slot0_1_enum
);
1471 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot2_3_enum
,
1472 RT5645_TDM_CTRL_1
, 4, rt5645_tdm_adc_swap_select
);
1474 static const struct snd_kcontrol_new rt5645_if1_adc2_in_mux
=
1475 SOC_DAPM_ENUM("IF1 ADC2 IN source", rt5645_tdm_adc_slot2_3_enum
);
1477 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_adc_slot4_5_enum
,
1478 RT5645_TDM_CTRL_1
, 2, rt5645_tdm_adc_swap_select
);
1480 static const struct snd_kcontrol_new rt5645_if1_adc3_in_mux
=
1481 SOC_DAPM_ENUM("IF1 ADC3 IN source", rt5645_tdm_adc_slot4_5_enum
);
1483 /* MX-79 [14:12][10:8][6:4][2:0] */
1484 static const char * const rt5645_tdm_dac_swap_select
[] = {
1485 "Slot0", "Slot1", "Slot2", "Slot3"
1488 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_dac0_enum
,
1489 RT5645_TDM_CTRL_3
, 12, rt5645_tdm_dac_swap_select
);
1491 static const struct snd_kcontrol_new rt5645_if1_dac0_tdm_sel_mux
=
1492 SOC_DAPM_ENUM("IF1 DAC0 source", rt5645_tdm_dac0_enum
);
1494 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_dac1_enum
,
1495 RT5645_TDM_CTRL_3
, 8, rt5645_tdm_dac_swap_select
);
1497 static const struct snd_kcontrol_new rt5645_if1_dac1_tdm_sel_mux
=
1498 SOC_DAPM_ENUM("IF1 DAC1 source", rt5645_tdm_dac1_enum
);
1500 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_dac2_enum
,
1501 RT5645_TDM_CTRL_3
, 4, rt5645_tdm_dac_swap_select
);
1503 static const struct snd_kcontrol_new rt5645_if1_dac2_tdm_sel_mux
=
1504 SOC_DAPM_ENUM("IF1 DAC2 source", rt5645_tdm_dac2_enum
);
1506 static SOC_ENUM_SINGLE_DECL(rt5645_tdm_dac3_enum
,
1507 RT5645_TDM_CTRL_3
, 0, rt5645_tdm_dac_swap_select
);
1509 static const struct snd_kcontrol_new rt5645_if1_dac3_tdm_sel_mux
=
1510 SOC_DAPM_ENUM("IF1 DAC3 source", rt5645_tdm_dac3_enum
);
1512 /* MX-7a [14:12][10:8][6:4][2:0] */
1513 static SOC_ENUM_SINGLE_DECL(rt5650_tdm_dac0_enum
,
1514 RT5650_TDM_CTRL_4
, 12, rt5645_tdm_dac_swap_select
);
1516 static const struct snd_kcontrol_new rt5650_if1_dac0_tdm_sel_mux
=
1517 SOC_DAPM_ENUM("IF1 DAC0 source", rt5650_tdm_dac0_enum
);
1519 static SOC_ENUM_SINGLE_DECL(rt5650_tdm_dac1_enum
,
1520 RT5650_TDM_CTRL_4
, 8, rt5645_tdm_dac_swap_select
);
1522 static const struct snd_kcontrol_new rt5650_if1_dac1_tdm_sel_mux
=
1523 SOC_DAPM_ENUM("IF1 DAC1 source", rt5650_tdm_dac1_enum
);
1525 static SOC_ENUM_SINGLE_DECL(rt5650_tdm_dac2_enum
,
1526 RT5650_TDM_CTRL_4
, 4, rt5645_tdm_dac_swap_select
);
1528 static const struct snd_kcontrol_new rt5650_if1_dac2_tdm_sel_mux
=
1529 SOC_DAPM_ENUM("IF1 DAC2 source", rt5650_tdm_dac2_enum
);
1531 static SOC_ENUM_SINGLE_DECL(rt5650_tdm_dac3_enum
,
1532 RT5650_TDM_CTRL_4
, 0, rt5645_tdm_dac_swap_select
);
1534 static const struct snd_kcontrol_new rt5650_if1_dac3_tdm_sel_mux
=
1535 SOC_DAPM_ENUM("IF1 DAC3 source", rt5650_tdm_dac3_enum
);
1538 static const char * const rt5650_a_dac1_src
[] = {
1539 "DAC1", "Stereo DAC Mixer"
1542 static SOC_ENUM_SINGLE_DECL(
1543 rt5650_a_dac1_l_enum
, RT5650_A_DAC_SOUR
,
1544 RT5650_A_DAC1_L_IN_SFT
, rt5650_a_dac1_src
);
1546 static const struct snd_kcontrol_new rt5650_a_dac1_l_mux
=
1547 SOC_DAPM_ENUM("A DAC1 L source", rt5650_a_dac1_l_enum
);
1549 static SOC_ENUM_SINGLE_DECL(
1550 rt5650_a_dac1_r_enum
, RT5650_A_DAC_SOUR
,
1551 RT5650_A_DAC1_R_IN_SFT
, rt5650_a_dac1_src
);
1553 static const struct snd_kcontrol_new rt5650_a_dac1_r_mux
=
1554 SOC_DAPM_ENUM("A DAC1 R source", rt5650_a_dac1_r_enum
);
1557 static const char * const rt5650_a_dac2_src
[] = {
1558 "Stereo DAC Mixer", "Mono DAC Mixer"
1561 static SOC_ENUM_SINGLE_DECL(
1562 rt5650_a_dac2_l_enum
, RT5650_A_DAC_SOUR
,
1563 RT5650_A_DAC2_L_IN_SFT
, rt5650_a_dac2_src
);
1565 static const struct snd_kcontrol_new rt5650_a_dac2_l_mux
=
1566 SOC_DAPM_ENUM("A DAC2 L source", rt5650_a_dac2_l_enum
);
1568 static SOC_ENUM_SINGLE_DECL(
1569 rt5650_a_dac2_r_enum
, RT5650_A_DAC_SOUR
,
1570 RT5650_A_DAC2_R_IN_SFT
, rt5650_a_dac2_src
);
1572 static const struct snd_kcontrol_new rt5650_a_dac2_r_mux
=
1573 SOC_DAPM_ENUM("A DAC2 R source", rt5650_a_dac2_r_enum
);
1576 static const char * const rt5645_if2_adc_in_src
[] = {
1577 "IF_ADC1", "IF_ADC2", "VAD_ADC"
1580 static SOC_ENUM_SINGLE_DECL(
1581 rt5645_if2_adc_in_enum
, RT5645_DIG_INF1_DATA
,
1582 RT5645_IF2_ADC_IN_SFT
, rt5645_if2_adc_in_src
);
1584 static const struct snd_kcontrol_new rt5645_if2_adc_in_mux
=
1585 SOC_DAPM_ENUM("IF2 ADC IN source", rt5645_if2_adc_in_enum
);
1588 static const char * const rt5645_if3_adc_in_src
[] = {
1589 "IF_ADC1", "IF_ADC2", "VAD_ADC"
1592 static SOC_ENUM_SINGLE_DECL(
1593 rt5645_if3_adc_in_enum
, RT5645_DIG_INF1_DATA
,
1594 RT5645_IF3_ADC_IN_SFT
, rt5645_if3_adc_in_src
);
1596 static const struct snd_kcontrol_new rt5645_if3_adc_in_mux
=
1597 SOC_DAPM_ENUM("IF3 ADC IN source", rt5645_if3_adc_in_enum
);
1599 /* MX-31 [15] [13] [11] [9] */
1600 static const char * const rt5645_pdm_src
[] = {
1601 "Mono DAC", "Stereo DAC"
1604 static SOC_ENUM_SINGLE_DECL(
1605 rt5645_pdm1_l_enum
, RT5645_PDM_OUT_CTRL
,
1606 RT5645_PDM1_L_SFT
, rt5645_pdm_src
);
1608 static const struct snd_kcontrol_new rt5645_pdm1_l_mux
=
1609 SOC_DAPM_ENUM("PDM1 L source", rt5645_pdm1_l_enum
);
1611 static SOC_ENUM_SINGLE_DECL(
1612 rt5645_pdm1_r_enum
, RT5645_PDM_OUT_CTRL
,
1613 RT5645_PDM1_R_SFT
, rt5645_pdm_src
);
1615 static const struct snd_kcontrol_new rt5645_pdm1_r_mux
=
1616 SOC_DAPM_ENUM("PDM1 R source", rt5645_pdm1_r_enum
);
1619 static const char * const rt5645_vad_adc_src
[] = {
1620 "Sto1 ADC L", "Mono ADC L", "Mono ADC R"
1623 static SOC_ENUM_SINGLE_DECL(
1624 rt5645_vad_adc_enum
, RT5645_VAD_CTRL4
,
1625 RT5645_VAD_SEL_SFT
, rt5645_vad_adc_src
);
1627 static const struct snd_kcontrol_new rt5645_vad_adc_mux
=
1628 SOC_DAPM_ENUM("VAD ADC source", rt5645_vad_adc_enum
);
1630 static const struct snd_kcontrol_new spk_l_vol_control
=
1631 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_SPK_VOL
,
1632 RT5645_L_MUTE_SFT
, 1, 1);
1634 static const struct snd_kcontrol_new spk_r_vol_control
=
1635 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_SPK_VOL
,
1636 RT5645_R_MUTE_SFT
, 1, 1);
1638 static const struct snd_kcontrol_new hp_l_vol_control
=
1639 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_HP_VOL
,
1640 RT5645_L_MUTE_SFT
, 1, 1);
1642 static const struct snd_kcontrol_new hp_r_vol_control
=
1643 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_HP_VOL
,
1644 RT5645_R_MUTE_SFT
, 1, 1);
1646 static const struct snd_kcontrol_new pdm1_l_vol_control
=
1647 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_PDM_OUT_CTRL
,
1648 RT5645_M_PDM1_L
, 1, 1);
1650 static const struct snd_kcontrol_new pdm1_r_vol_control
=
1651 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5645_PDM_OUT_CTRL
,
1652 RT5645_M_PDM1_R
, 1, 1);
1654 static void hp_amp_power(struct snd_soc_codec
*codec
, int on
)
1656 static int hp_amp_power_count
;
1657 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
1660 if (hp_amp_power_count
<= 0) {
1661 if (rt5645
->codec_type
== CODEC_TYPE_RT5650
) {
1662 snd_soc_write(codec
, RT5645_DEPOP_M2
, 0x3100);
1663 snd_soc_write(codec
, RT5645_CHARGE_PUMP
,
1665 snd_soc_write(codec
, RT5645_DEPOP_M1
, 0x000d);
1666 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1667 RT5645_HP_DCC_INT1
, 0x9f01);
1669 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1670 RT5645_HP_CO_MASK
, RT5645_HP_CO_EN
);
1671 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1673 snd_soc_write(codec
, RT5645_DEPOP_M3
, 0x0737);
1674 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1675 RT5645_MAMP_INT_REG2
, 0xfc00);
1676 snd_soc_write(codec
, RT5645_DEPOP_M2
, 0x1140);
1678 rt5645
->hp_on
= true;
1680 /* depop parameters */
1681 snd_soc_update_bits(codec
, RT5645_DEPOP_M2
,
1682 RT5645_DEPOP_MASK
, RT5645_DEPOP_MAN
);
1683 snd_soc_write(codec
, RT5645_DEPOP_M1
, 0x000d);
1684 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1685 RT5645_HP_DCC_INT1
, 0x9f01);
1687 /* headphone amp power on */
1688 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1689 RT5645_PWR_FV1
| RT5645_PWR_FV2
, 0);
1690 snd_soc_update_bits(codec
, RT5645_PWR_VOL
,
1691 RT5645_PWR_HV_L
| RT5645_PWR_HV_R
,
1692 RT5645_PWR_HV_L
| RT5645_PWR_HV_R
);
1693 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1694 RT5645_PWR_HP_L
| RT5645_PWR_HP_R
|
1696 RT5645_PWR_HP_L
| RT5645_PWR_HP_R
|
1699 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1700 RT5645_PWR_FV1
| RT5645_PWR_FV2
,
1701 RT5645_PWR_FV1
| RT5645_PWR_FV2
);
1703 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1704 RT5645_HP_CO_MASK
| RT5645_HP_SG_MASK
,
1705 RT5645_HP_CO_EN
| RT5645_HP_SG_EN
);
1706 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1708 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1712 hp_amp_power_count
++;
1714 hp_amp_power_count
--;
1715 if (hp_amp_power_count
<= 0) {
1716 if (rt5645
->codec_type
== CODEC_TYPE_RT5650
) {
1717 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1719 snd_soc_write(codec
, RT5645_DEPOP_M3
, 0x0737);
1720 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1721 RT5645_MAMP_INT_REG2
, 0xfc00);
1722 snd_soc_write(codec
, RT5645_DEPOP_M2
, 0x1140);
1724 snd_soc_write(codec
, RT5645_DEPOP_M1
, 0x0001);
1727 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1729 RT5645_HP_L_SMT_MASK
|
1730 RT5645_HP_R_SMT_MASK
,
1732 RT5645_HP_L_SMT_DIS
|
1733 RT5645_HP_R_SMT_DIS
);
1734 /* headphone amp power down */
1735 snd_soc_write(codec
, RT5645_DEPOP_M1
, 0x0000);
1736 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1737 RT5645_PWR_HP_L
| RT5645_PWR_HP_R
|
1739 snd_soc_update_bits(codec
, RT5645_DEPOP_M2
,
1740 RT5645_DEPOP_MASK
, 0);
1746 static int rt5645_hp_event(struct snd_soc_dapm_widget
*w
,
1747 struct snd_kcontrol
*kcontrol
, int event
)
1749 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1750 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
1753 case SND_SOC_DAPM_POST_PMU
:
1754 hp_amp_power(codec
, 1);
1755 /* headphone unmute sequence */
1756 if (rt5645
->codec_type
== CODEC_TYPE_RT5645
) {
1757 snd_soc_update_bits(codec
, RT5645_DEPOP_M3
,
1758 RT5645_CP_FQ1_MASK
| RT5645_CP_FQ2_MASK
|
1760 (RT5645_CP_FQ_192_KHZ
<< RT5645_CP_FQ1_SFT
) |
1761 (RT5645_CP_FQ_12_KHZ
<< RT5645_CP_FQ2_SFT
) |
1762 (RT5645_CP_FQ_192_KHZ
<< RT5645_CP_FQ3_SFT
));
1763 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1764 RT5645_MAMP_INT_REG2
, 0xfc00);
1765 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1766 RT5645_SMT_TRIG_MASK
, RT5645_SMT_TRIG_EN
);
1767 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1768 RT5645_RSTN_MASK
, RT5645_RSTN_EN
);
1769 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1770 RT5645_RSTN_MASK
| RT5645_HP_L_SMT_MASK
|
1771 RT5645_HP_R_SMT_MASK
, RT5645_RSTN_DIS
|
1772 RT5645_HP_L_SMT_EN
| RT5645_HP_R_SMT_EN
);
1774 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1775 RT5645_HP_SG_MASK
| RT5645_HP_L_SMT_MASK
|
1776 RT5645_HP_R_SMT_MASK
, RT5645_HP_SG_DIS
|
1777 RT5645_HP_L_SMT_DIS
| RT5645_HP_R_SMT_DIS
);
1781 case SND_SOC_DAPM_PRE_PMD
:
1782 /* headphone mute sequence */
1783 if (rt5645
->codec_type
== CODEC_TYPE_RT5645
) {
1784 snd_soc_update_bits(codec
, RT5645_DEPOP_M3
,
1785 RT5645_CP_FQ1_MASK
| RT5645_CP_FQ2_MASK
|
1787 (RT5645_CP_FQ_96_KHZ
<< RT5645_CP_FQ1_SFT
) |
1788 (RT5645_CP_FQ_12_KHZ
<< RT5645_CP_FQ2_SFT
) |
1789 (RT5645_CP_FQ_96_KHZ
<< RT5645_CP_FQ3_SFT
));
1790 regmap_write(rt5645
->regmap
, RT5645_PR_BASE
+
1791 RT5645_MAMP_INT_REG2
, 0xfc00);
1792 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1793 RT5645_HP_SG_MASK
, RT5645_HP_SG_EN
);
1794 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1795 RT5645_RSTP_MASK
, RT5645_RSTP_EN
);
1796 snd_soc_update_bits(codec
, RT5645_DEPOP_M1
,
1797 RT5645_RSTP_MASK
| RT5645_HP_L_SMT_MASK
|
1798 RT5645_HP_R_SMT_MASK
, RT5645_RSTP_DIS
|
1799 RT5645_HP_L_SMT_EN
| RT5645_HP_R_SMT_EN
);
1802 hp_amp_power(codec
, 0);
1812 static int rt5645_spk_event(struct snd_soc_dapm_widget
*w
,
1813 struct snd_kcontrol
*kcontrol
, int event
)
1815 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1818 case SND_SOC_DAPM_POST_PMU
:
1819 rt5645_enable_hweq(codec
);
1820 snd_soc_update_bits(codec
, RT5645_PWR_DIG1
,
1821 RT5645_PWR_CLS_D
| RT5645_PWR_CLS_D_R
|
1823 RT5645_PWR_CLS_D
| RT5645_PWR_CLS_D_R
|
1824 RT5645_PWR_CLS_D_L
);
1825 snd_soc_update_bits(codec
, RT5645_GEN_CTRL3
,
1826 RT5645_DET_CLK_MASK
, RT5645_DET_CLK_MODE1
);
1829 case SND_SOC_DAPM_PRE_PMD
:
1830 snd_soc_update_bits(codec
, RT5645_GEN_CTRL3
,
1831 RT5645_DET_CLK_MASK
, RT5645_DET_CLK_DIS
);
1832 snd_soc_write(codec
, RT5645_EQ_CTRL2
, 0);
1833 snd_soc_update_bits(codec
, RT5645_PWR_DIG1
,
1834 RT5645_PWR_CLS_D
| RT5645_PWR_CLS_D_R
|
1835 RT5645_PWR_CLS_D_L
, 0);
1845 static int rt5645_lout_event(struct snd_soc_dapm_widget
*w
,
1846 struct snd_kcontrol
*kcontrol
, int event
)
1848 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1851 case SND_SOC_DAPM_POST_PMU
:
1852 hp_amp_power(codec
, 1);
1853 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1854 RT5645_PWR_LM
, RT5645_PWR_LM
);
1855 snd_soc_update_bits(codec
, RT5645_LOUT1
,
1856 RT5645_L_MUTE
| RT5645_R_MUTE
, 0);
1859 case SND_SOC_DAPM_PRE_PMD
:
1860 snd_soc_update_bits(codec
, RT5645_LOUT1
,
1861 RT5645_L_MUTE
| RT5645_R_MUTE
,
1862 RT5645_L_MUTE
| RT5645_R_MUTE
);
1863 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
1865 hp_amp_power(codec
, 0);
1875 static int rt5645_bst2_event(struct snd_soc_dapm_widget
*w
,
1876 struct snd_kcontrol
*kcontrol
, int event
)
1878 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1881 case SND_SOC_DAPM_POST_PMU
:
1882 snd_soc_update_bits(codec
, RT5645_PWR_ANLG2
,
1883 RT5645_PWR_BST2_P
, RT5645_PWR_BST2_P
);
1886 case SND_SOC_DAPM_PRE_PMD
:
1887 snd_soc_update_bits(codec
, RT5645_PWR_ANLG2
,
1888 RT5645_PWR_BST2_P
, 0);
1898 static int rt5650_hp_event(struct snd_soc_dapm_widget
*w
,
1899 struct snd_kcontrol
*k
, int event
)
1901 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1902 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
1905 case SND_SOC_DAPM_POST_PMU
:
1906 if (rt5645
->hp_on
) {
1908 rt5645
->hp_on
= false;
1919 static const struct snd_soc_dapm_widget rt5645_dapm_widgets
[] = {
1920 SND_SOC_DAPM_SUPPLY("LDO2", RT5645_PWR_MIXER
,
1921 RT5645_PWR_LDO2_BIT
, 0, NULL
, 0),
1922 SND_SOC_DAPM_SUPPLY("PLL1", RT5645_PWR_ANLG2
,
1923 RT5645_PWR_PLL_BIT
, 0, NULL
, 0),
1925 SND_SOC_DAPM_SUPPLY("JD Power", RT5645_PWR_ANLG2
,
1926 RT5645_PWR_JD1_BIT
, 0, NULL
, 0),
1927 SND_SOC_DAPM_SUPPLY("Mic Det Power", RT5645_PWR_VOL
,
1928 RT5645_PWR_MIC_DET_BIT
, 0, NULL
, 0),
1931 SND_SOC_DAPM_SUPPLY_S("I2S1 ASRC", 1, RT5645_ASRC_1
,
1933 SND_SOC_DAPM_SUPPLY_S("I2S2 ASRC", 1, RT5645_ASRC_1
,
1935 SND_SOC_DAPM_SUPPLY_S("DAC STO ASRC", 1, RT5645_ASRC_1
,
1937 SND_SOC_DAPM_SUPPLY_S("DAC MONO L ASRC", 1, RT5645_ASRC_1
,
1939 SND_SOC_DAPM_SUPPLY_S("DAC MONO R ASRC", 1, RT5645_ASRC_1
,
1941 SND_SOC_DAPM_SUPPLY_S("DMIC STO1 ASRC", 1, RT5645_ASRC_1
,
1943 SND_SOC_DAPM_SUPPLY_S("DMIC MONO L ASRC", 1, RT5645_ASRC_1
,
1945 SND_SOC_DAPM_SUPPLY_S("DMIC MONO R ASRC", 1, RT5645_ASRC_1
,
1947 SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5645_ASRC_1
,
1949 SND_SOC_DAPM_SUPPLY_S("ADC MONO L ASRC", 1, RT5645_ASRC_1
,
1951 SND_SOC_DAPM_SUPPLY_S("ADC MONO R ASRC", 1, RT5645_ASRC_1
,
1956 SND_SOC_DAPM_MICBIAS("micbias1", RT5645_PWR_ANLG2
,
1957 RT5645_PWR_MB1_BIT
, 0),
1958 SND_SOC_DAPM_MICBIAS("micbias2", RT5645_PWR_ANLG2
,
1959 RT5645_PWR_MB2_BIT
, 0),
1961 SND_SOC_DAPM_INPUT("DMIC L1"),
1962 SND_SOC_DAPM_INPUT("DMIC R1"),
1963 SND_SOC_DAPM_INPUT("DMIC L2"),
1964 SND_SOC_DAPM_INPUT("DMIC R2"),
1966 SND_SOC_DAPM_INPUT("IN1P"),
1967 SND_SOC_DAPM_INPUT("IN1N"),
1968 SND_SOC_DAPM_INPUT("IN2P"),
1969 SND_SOC_DAPM_INPUT("IN2N"),
1971 SND_SOC_DAPM_INPUT("Haptic Generator"),
1973 SND_SOC_DAPM_PGA("DMIC1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1974 SND_SOC_DAPM_PGA("DMIC2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1975 SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM
, 0, 0,
1976 set_dmic_clk
, SND_SOC_DAPM_PRE_PMU
),
1977 SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5645_DMIC_CTRL1
,
1978 RT5645_DMIC_1_EN_SFT
, 0, NULL
, 0),
1979 SND_SOC_DAPM_SUPPLY("DMIC2 Power", RT5645_DMIC_CTRL1
,
1980 RT5645_DMIC_2_EN_SFT
, 0, NULL
, 0),
1982 SND_SOC_DAPM_PGA("BST1", RT5645_PWR_ANLG2
,
1983 RT5645_PWR_BST1_BIT
, 0, NULL
, 0),
1984 SND_SOC_DAPM_PGA_E("BST2", RT5645_PWR_ANLG2
,
1985 RT5645_PWR_BST2_BIT
, 0, NULL
, 0, rt5645_bst2_event
,
1986 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
1988 SND_SOC_DAPM_PGA("INL VOL", RT5645_PWR_VOL
,
1989 RT5645_PWR_IN_L_BIT
, 0, NULL
, 0),
1990 SND_SOC_DAPM_PGA("INR VOL", RT5645_PWR_VOL
,
1991 RT5645_PWR_IN_R_BIT
, 0, NULL
, 0),
1993 SND_SOC_DAPM_MIXER("RECMIXL", RT5645_PWR_MIXER
, RT5645_PWR_RM_L_BIT
,
1994 0, rt5645_rec_l_mix
, ARRAY_SIZE(rt5645_rec_l_mix
)),
1995 SND_SOC_DAPM_MIXER("RECMIXR", RT5645_PWR_MIXER
, RT5645_PWR_RM_R_BIT
,
1996 0, rt5645_rec_r_mix
, ARRAY_SIZE(rt5645_rec_r_mix
)),
1998 SND_SOC_DAPM_ADC("ADC L", NULL
, SND_SOC_NOPM
, 0, 0),
1999 SND_SOC_DAPM_ADC("ADC R", NULL
, SND_SOC_NOPM
, 0, 0),
2001 SND_SOC_DAPM_SUPPLY("ADC L power", RT5645_PWR_DIG1
,
2002 RT5645_PWR_ADC_L_BIT
, 0, NULL
, 0),
2003 SND_SOC_DAPM_SUPPLY("ADC R power", RT5645_PWR_DIG1
,
2004 RT5645_PWR_ADC_R_BIT
, 0, NULL
, 0),
2007 SND_SOC_DAPM_MUX("Stereo1 DMIC Mux", SND_SOC_NOPM
, 0, 0,
2008 &rt5645_sto1_dmic_mux
),
2009 SND_SOC_DAPM_MUX("Stereo1 ADC L2 Mux", SND_SOC_NOPM
, 0, 0,
2010 &rt5645_sto_adc2_mux
),
2011 SND_SOC_DAPM_MUX("Stereo1 ADC R2 Mux", SND_SOC_NOPM
, 0, 0,
2012 &rt5645_sto_adc2_mux
),
2013 SND_SOC_DAPM_MUX("Stereo1 ADC L1 Mux", SND_SOC_NOPM
, 0, 0,
2014 &rt5645_sto_adc1_mux
),
2015 SND_SOC_DAPM_MUX("Stereo1 ADC R1 Mux", SND_SOC_NOPM
, 0, 0,
2016 &rt5645_sto_adc1_mux
),
2017 SND_SOC_DAPM_MUX("Mono DMIC L Mux", SND_SOC_NOPM
, 0, 0,
2018 &rt5645_mono_dmic_l_mux
),
2019 SND_SOC_DAPM_MUX("Mono DMIC R Mux", SND_SOC_NOPM
, 0, 0,
2020 &rt5645_mono_dmic_r_mux
),
2021 SND_SOC_DAPM_MUX("Mono ADC L2 Mux", SND_SOC_NOPM
, 0, 0,
2022 &rt5645_mono_adc_l2_mux
),
2023 SND_SOC_DAPM_MUX("Mono ADC L1 Mux", SND_SOC_NOPM
, 0, 0,
2024 &rt5645_mono_adc_l1_mux
),
2025 SND_SOC_DAPM_MUX("Mono ADC R1 Mux", SND_SOC_NOPM
, 0, 0,
2026 &rt5645_mono_adc_r1_mux
),
2027 SND_SOC_DAPM_MUX("Mono ADC R2 Mux", SND_SOC_NOPM
, 0, 0,
2028 &rt5645_mono_adc_r2_mux
),
2031 SND_SOC_DAPM_SUPPLY_S("adc stereo1 filter", 1, RT5645_PWR_DIG2
,
2032 RT5645_PWR_ADC_S1F_BIT
, 0, NULL
, 0),
2033 SND_SOC_DAPM_MIXER_E("Sto1 ADC MIXL", SND_SOC_NOPM
, 0, 0,
2034 rt5645_sto1_adc_l_mix
, ARRAY_SIZE(rt5645_sto1_adc_l_mix
),
2036 SND_SOC_DAPM_MIXER_E("Sto1 ADC MIXR", SND_SOC_NOPM
, 0, 0,
2037 rt5645_sto1_adc_r_mix
, ARRAY_SIZE(rt5645_sto1_adc_r_mix
),
2039 SND_SOC_DAPM_SUPPLY_S("adc mono left filter", 1, RT5645_PWR_DIG2
,
2040 RT5645_PWR_ADC_MF_L_BIT
, 0, NULL
, 0),
2041 SND_SOC_DAPM_MIXER_E("Mono ADC MIXL", SND_SOC_NOPM
, 0, 0,
2042 rt5645_mono_adc_l_mix
, ARRAY_SIZE(rt5645_mono_adc_l_mix
),
2044 SND_SOC_DAPM_SUPPLY_S("adc mono right filter", 1, RT5645_PWR_DIG2
,
2045 RT5645_PWR_ADC_MF_R_BIT
, 0, NULL
, 0),
2046 SND_SOC_DAPM_MIXER_E("Mono ADC MIXR", SND_SOC_NOPM
, 0, 0,
2047 rt5645_mono_adc_r_mix
, ARRAY_SIZE(rt5645_mono_adc_r_mix
),
2051 SND_SOC_DAPM_PGA("Stereo1 ADC MIXL", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2052 SND_SOC_DAPM_PGA("Stereo1 ADC MIXR", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2053 SND_SOC_DAPM_PGA("Sto2 ADC LR MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2054 SND_SOC_DAPM_PGA("VAD_ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2055 SND_SOC_DAPM_PGA("IF_ADC1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2056 SND_SOC_DAPM_PGA("IF_ADC2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2057 SND_SOC_DAPM_PGA("IF1_ADC1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2058 SND_SOC_DAPM_PGA("IF1_ADC2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2059 SND_SOC_DAPM_PGA("IF1_ADC3", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2060 SND_SOC_DAPM_PGA("IF1_ADC4", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2063 SND_SOC_DAPM_MUX("IF2 ADC Mux", SND_SOC_NOPM
,
2064 0, 0, &rt5645_if2_adc_in_mux
),
2066 /* Digital Interface */
2067 SND_SOC_DAPM_SUPPLY("I2S1", RT5645_PWR_DIG1
,
2068 RT5645_PWR_I2S1_BIT
, 0, NULL
, 0),
2069 SND_SOC_DAPM_PGA("IF1 DAC0", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2070 SND_SOC_DAPM_PGA("IF1 DAC1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2071 SND_SOC_DAPM_PGA("IF1 DAC2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2072 SND_SOC_DAPM_PGA("IF1 DAC3", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2073 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2074 SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2075 SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2076 SND_SOC_DAPM_SUPPLY("I2S2", RT5645_PWR_DIG1
,
2077 RT5645_PWR_I2S2_BIT
, 0, NULL
, 0),
2078 SND_SOC_DAPM_PGA("IF2 DAC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2079 SND_SOC_DAPM_PGA("IF2 DAC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2080 SND_SOC_DAPM_PGA("IF2 DAC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2081 SND_SOC_DAPM_PGA("IF2 ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2083 /* Digital Interface Select */
2084 SND_SOC_DAPM_MUX("VAD ADC Mux", SND_SOC_NOPM
,
2085 0, 0, &rt5645_vad_adc_mux
),
2087 /* Audio Interface */
2088 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM
, 0, 0),
2089 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM
, 0, 0),
2090 SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Playback", 0, SND_SOC_NOPM
, 0, 0),
2091 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, SND_SOC_NOPM
, 0, 0),
2094 /* DAC mixer before sound effect */
2095 SND_SOC_DAPM_MIXER("DAC1 MIXL", SND_SOC_NOPM
, 0, 0,
2096 rt5645_dac_l_mix
, ARRAY_SIZE(rt5645_dac_l_mix
)),
2097 SND_SOC_DAPM_MIXER("DAC1 MIXR", SND_SOC_NOPM
, 0, 0,
2098 rt5645_dac_r_mix
, ARRAY_SIZE(rt5645_dac_r_mix
)),
2100 /* DAC2 channel Mux */
2101 SND_SOC_DAPM_MUX("DAC L2 Mux", SND_SOC_NOPM
, 0, 0, &rt5645_dac_l2_mux
),
2102 SND_SOC_DAPM_MUX("DAC R2 Mux", SND_SOC_NOPM
, 0, 0, &rt5645_dac_r2_mux
),
2103 SND_SOC_DAPM_PGA("DAC L2 Volume", RT5645_PWR_DIG1
,
2104 RT5645_PWR_DAC_L2_BIT
, 0, NULL
, 0),
2105 SND_SOC_DAPM_PGA("DAC R2 Volume", RT5645_PWR_DIG1
,
2106 RT5645_PWR_DAC_R2_BIT
, 0, NULL
, 0),
2108 SND_SOC_DAPM_MUX("DAC1 L Mux", SND_SOC_NOPM
, 0, 0, &rt5645_dac1l_mux
),
2109 SND_SOC_DAPM_MUX("DAC1 R Mux", SND_SOC_NOPM
, 0, 0, &rt5645_dac1r_mux
),
2112 SND_SOC_DAPM_SUPPLY_S("dac stereo1 filter", 1, RT5645_PWR_DIG2
,
2113 RT5645_PWR_DAC_S1F_BIT
, 0, NULL
, 0),
2114 SND_SOC_DAPM_SUPPLY_S("dac mono left filter", 1, RT5645_PWR_DIG2
,
2115 RT5645_PWR_DAC_MF_L_BIT
, 0, NULL
, 0),
2116 SND_SOC_DAPM_SUPPLY_S("dac mono right filter", 1, RT5645_PWR_DIG2
,
2117 RT5645_PWR_DAC_MF_R_BIT
, 0, NULL
, 0),
2118 SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM
, 0, 0,
2119 rt5645_sto_dac_l_mix
, ARRAY_SIZE(rt5645_sto_dac_l_mix
)),
2120 SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM
, 0, 0,
2121 rt5645_sto_dac_r_mix
, ARRAY_SIZE(rt5645_sto_dac_r_mix
)),
2122 SND_SOC_DAPM_MIXER("Mono DAC MIXL", SND_SOC_NOPM
, 0, 0,
2123 rt5645_mono_dac_l_mix
, ARRAY_SIZE(rt5645_mono_dac_l_mix
)),
2124 SND_SOC_DAPM_MIXER("Mono DAC MIXR", SND_SOC_NOPM
, 0, 0,
2125 rt5645_mono_dac_r_mix
, ARRAY_SIZE(rt5645_mono_dac_r_mix
)),
2126 SND_SOC_DAPM_MIXER("DAC MIXL", SND_SOC_NOPM
, 0, 0,
2127 rt5645_dig_l_mix
, ARRAY_SIZE(rt5645_dig_l_mix
)),
2128 SND_SOC_DAPM_MIXER("DAC MIXR", SND_SOC_NOPM
, 0, 0,
2129 rt5645_dig_r_mix
, ARRAY_SIZE(rt5645_dig_r_mix
)),
2132 SND_SOC_DAPM_DAC("DAC L1", NULL
, RT5645_PWR_DIG1
, RT5645_PWR_DAC_L1_BIT
,
2134 SND_SOC_DAPM_DAC("DAC L2", NULL
, RT5645_PWR_DIG1
, RT5645_PWR_DAC_L2_BIT
,
2136 SND_SOC_DAPM_DAC("DAC R1", NULL
, RT5645_PWR_DIG1
, RT5645_PWR_DAC_R1_BIT
,
2138 SND_SOC_DAPM_DAC("DAC R2", NULL
, RT5645_PWR_DIG1
, RT5645_PWR_DAC_R2_BIT
,
2141 SND_SOC_DAPM_MIXER("SPK MIXL", RT5645_PWR_MIXER
, RT5645_PWR_SM_L_BIT
,
2142 0, rt5645_spk_l_mix
, ARRAY_SIZE(rt5645_spk_l_mix
)),
2143 SND_SOC_DAPM_MIXER("SPK MIXR", RT5645_PWR_MIXER
, RT5645_PWR_SM_R_BIT
,
2144 0, rt5645_spk_r_mix
, ARRAY_SIZE(rt5645_spk_r_mix
)),
2145 SND_SOC_DAPM_MIXER("OUT MIXL", RT5645_PWR_MIXER
, RT5645_PWR_OM_L_BIT
,
2146 0, rt5645_out_l_mix
, ARRAY_SIZE(rt5645_out_l_mix
)),
2147 SND_SOC_DAPM_MIXER("OUT MIXR", RT5645_PWR_MIXER
, RT5645_PWR_OM_R_BIT
,
2148 0, rt5645_out_r_mix
, ARRAY_SIZE(rt5645_out_r_mix
)),
2150 SND_SOC_DAPM_SWITCH("SPKVOL L", RT5645_PWR_VOL
, RT5645_PWR_SV_L_BIT
, 0,
2151 &spk_l_vol_control
),
2152 SND_SOC_DAPM_SWITCH("SPKVOL R", RT5645_PWR_VOL
, RT5645_PWR_SV_R_BIT
, 0,
2153 &spk_r_vol_control
),
2154 SND_SOC_DAPM_MIXER("HPOVOL MIXL", RT5645_PWR_VOL
, RT5645_PWR_HV_L_BIT
,
2155 0, rt5645_hpvoll_mix
, ARRAY_SIZE(rt5645_hpvoll_mix
)),
2156 SND_SOC_DAPM_MIXER("HPOVOL MIXR", RT5645_PWR_VOL
, RT5645_PWR_HV_R_BIT
,
2157 0, rt5645_hpvolr_mix
, ARRAY_SIZE(rt5645_hpvolr_mix
)),
2158 SND_SOC_DAPM_SUPPLY("HPOVOL MIXL Power", RT5645_PWR_MIXER
,
2159 RT5645_PWR_HM_L_BIT
, 0, NULL
, 0),
2160 SND_SOC_DAPM_SUPPLY("HPOVOL MIXR Power", RT5645_PWR_MIXER
,
2161 RT5645_PWR_HM_R_BIT
, 0, NULL
, 0),
2162 SND_SOC_DAPM_PGA("DAC 1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2163 SND_SOC_DAPM_PGA("DAC 2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2164 SND_SOC_DAPM_PGA("HPOVOL", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2165 SND_SOC_DAPM_SWITCH("HPOVOL L", SND_SOC_NOPM
, 0, 0, &hp_l_vol_control
),
2166 SND_SOC_DAPM_SWITCH("HPOVOL R", SND_SOC_NOPM
, 0, 0, &hp_r_vol_control
),
2168 /* HPO/LOUT/Mono Mixer */
2169 SND_SOC_DAPM_MIXER("SPOL MIX", SND_SOC_NOPM
, 0, 0, rt5645_spo_l_mix
,
2170 ARRAY_SIZE(rt5645_spo_l_mix
)),
2171 SND_SOC_DAPM_MIXER("SPOR MIX", SND_SOC_NOPM
, 0, 0, rt5645_spo_r_mix
,
2172 ARRAY_SIZE(rt5645_spo_r_mix
)),
2173 SND_SOC_DAPM_MIXER("HPO MIX", SND_SOC_NOPM
, 0, 0, rt5645_hpo_mix
,
2174 ARRAY_SIZE(rt5645_hpo_mix
)),
2175 SND_SOC_DAPM_MIXER("LOUT MIX", SND_SOC_NOPM
, 0, 0, rt5645_lout_mix
,
2176 ARRAY_SIZE(rt5645_lout_mix
)),
2178 SND_SOC_DAPM_PGA_S("HP amp", 1, SND_SOC_NOPM
, 0, 0, rt5645_hp_event
,
2179 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
2180 SND_SOC_DAPM_PGA_S("LOUT amp", 1, SND_SOC_NOPM
, 0, 0, rt5645_lout_event
,
2181 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
2182 SND_SOC_DAPM_PGA_S("SPK amp", 2, SND_SOC_NOPM
, 0, 0, rt5645_spk_event
,
2183 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
2186 SND_SOC_DAPM_SUPPLY("PDM1 Power", RT5645_PWR_DIG2
, RT5645_PWR_PDM1_BIT
,
2188 SND_SOC_DAPM_MUX("PDM1 L Mux", SND_SOC_NOPM
, 0, 0, &rt5645_pdm1_l_mux
),
2189 SND_SOC_DAPM_MUX("PDM1 R Mux", SND_SOC_NOPM
, 0, 0, &rt5645_pdm1_r_mux
),
2191 SND_SOC_DAPM_SWITCH("PDM1 L", SND_SOC_NOPM
, 0, 0, &pdm1_l_vol_control
),
2192 SND_SOC_DAPM_SWITCH("PDM1 R", SND_SOC_NOPM
, 0, 0, &pdm1_r_vol_control
),
2195 SND_SOC_DAPM_OUTPUT("HPOL"),
2196 SND_SOC_DAPM_OUTPUT("HPOR"),
2197 SND_SOC_DAPM_OUTPUT("LOUTL"),
2198 SND_SOC_DAPM_OUTPUT("LOUTR"),
2199 SND_SOC_DAPM_OUTPUT("PDM1L"),
2200 SND_SOC_DAPM_OUTPUT("PDM1R"),
2201 SND_SOC_DAPM_OUTPUT("SPOL"),
2202 SND_SOC_DAPM_OUTPUT("SPOR"),
2203 SND_SOC_DAPM_POST("DAPM_POST", rt5650_hp_event
),
2206 static const struct snd_soc_dapm_widget rt5645_specific_dapm_widgets
[] = {
2207 SND_SOC_DAPM_MUX("RT5645 IF1 DAC1 L Mux", SND_SOC_NOPM
, 0, 0,
2208 &rt5645_if1_dac0_tdm_sel_mux
),
2209 SND_SOC_DAPM_MUX("RT5645 IF1 DAC1 R Mux", SND_SOC_NOPM
, 0, 0,
2210 &rt5645_if1_dac1_tdm_sel_mux
),
2211 SND_SOC_DAPM_MUX("RT5645 IF1 DAC2 L Mux", SND_SOC_NOPM
, 0, 0,
2212 &rt5645_if1_dac2_tdm_sel_mux
),
2213 SND_SOC_DAPM_MUX("RT5645 IF1 DAC2 R Mux", SND_SOC_NOPM
, 0, 0,
2214 &rt5645_if1_dac3_tdm_sel_mux
),
2215 SND_SOC_DAPM_MUX("RT5645 IF1 ADC Mux", SND_SOC_NOPM
,
2216 0, 0, &rt5645_if1_adc_in_mux
),
2217 SND_SOC_DAPM_MUX("RT5645 IF1 ADC1 Swap Mux", SND_SOC_NOPM
,
2218 0, 0, &rt5645_if1_adc1_in_mux
),
2219 SND_SOC_DAPM_MUX("RT5645 IF1 ADC2 Swap Mux", SND_SOC_NOPM
,
2220 0, 0, &rt5645_if1_adc2_in_mux
),
2221 SND_SOC_DAPM_MUX("RT5645 IF1 ADC3 Swap Mux", SND_SOC_NOPM
,
2222 0, 0, &rt5645_if1_adc3_in_mux
),
2225 static const struct snd_soc_dapm_widget rt5650_specific_dapm_widgets
[] = {
2226 SND_SOC_DAPM_MUX("A DAC1 L Mux", SND_SOC_NOPM
,
2227 0, 0, &rt5650_a_dac1_l_mux
),
2228 SND_SOC_DAPM_MUX("A DAC1 R Mux", SND_SOC_NOPM
,
2229 0, 0, &rt5650_a_dac1_r_mux
),
2230 SND_SOC_DAPM_MUX("A DAC2 L Mux", SND_SOC_NOPM
,
2231 0, 0, &rt5650_a_dac2_l_mux
),
2232 SND_SOC_DAPM_MUX("A DAC2 R Mux", SND_SOC_NOPM
,
2233 0, 0, &rt5650_a_dac2_r_mux
),
2235 SND_SOC_DAPM_MUX("RT5650 IF1 ADC1 Swap Mux", SND_SOC_NOPM
,
2236 0, 0, &rt5650_if1_adc1_in_mux
),
2237 SND_SOC_DAPM_MUX("RT5650 IF1 ADC2 Swap Mux", SND_SOC_NOPM
,
2238 0, 0, &rt5650_if1_adc2_in_mux
),
2239 SND_SOC_DAPM_MUX("RT5650 IF1 ADC3 Swap Mux", SND_SOC_NOPM
,
2240 0, 0, &rt5650_if1_adc3_in_mux
),
2241 SND_SOC_DAPM_MUX("RT5650 IF1 ADC Mux", SND_SOC_NOPM
,
2242 0, 0, &rt5650_if1_adc_in_mux
),
2244 SND_SOC_DAPM_MUX("RT5650 IF1 DAC1 L Mux", SND_SOC_NOPM
, 0, 0,
2245 &rt5650_if1_dac0_tdm_sel_mux
),
2246 SND_SOC_DAPM_MUX("RT5650 IF1 DAC1 R Mux", SND_SOC_NOPM
, 0, 0,
2247 &rt5650_if1_dac1_tdm_sel_mux
),
2248 SND_SOC_DAPM_MUX("RT5650 IF1 DAC2 L Mux", SND_SOC_NOPM
, 0, 0,
2249 &rt5650_if1_dac2_tdm_sel_mux
),
2250 SND_SOC_DAPM_MUX("RT5650 IF1 DAC2 R Mux", SND_SOC_NOPM
, 0, 0,
2251 &rt5650_if1_dac3_tdm_sel_mux
),
2254 static const struct snd_soc_dapm_route rt5645_dapm_routes
[] = {
2255 { "adc stereo1 filter", NULL
, "ADC STO1 ASRC", is_using_asrc
},
2256 { "adc mono left filter", NULL
, "ADC MONO L ASRC", is_using_asrc
},
2257 { "adc mono right filter", NULL
, "ADC MONO R ASRC", is_using_asrc
},
2258 { "dac mono left filter", NULL
, "DAC MONO L ASRC", is_using_asrc
},
2259 { "dac mono right filter", NULL
, "DAC MONO R ASRC", is_using_asrc
},
2260 { "dac stereo1 filter", NULL
, "DAC STO ASRC", is_using_asrc
},
2262 { "I2S1", NULL
, "I2S1 ASRC" },
2263 { "I2S2", NULL
, "I2S2 ASRC" },
2265 { "IN1P", NULL
, "LDO2" },
2266 { "IN2P", NULL
, "LDO2" },
2268 { "DMIC1", NULL
, "DMIC L1" },
2269 { "DMIC1", NULL
, "DMIC R1" },
2270 { "DMIC2", NULL
, "DMIC L2" },
2271 { "DMIC2", NULL
, "DMIC R2" },
2273 { "BST1", NULL
, "IN1P" },
2274 { "BST1", NULL
, "IN1N" },
2275 { "BST1", NULL
, "JD Power" },
2276 { "BST1", NULL
, "Mic Det Power" },
2277 { "BST2", NULL
, "IN2P" },
2278 { "BST2", NULL
, "IN2N" },
2280 { "INL VOL", NULL
, "IN2P" },
2281 { "INR VOL", NULL
, "IN2N" },
2283 { "RECMIXL", "HPOL Switch", "HPOL" },
2284 { "RECMIXL", "INL Switch", "INL VOL" },
2285 { "RECMIXL", "BST2 Switch", "BST2" },
2286 { "RECMIXL", "BST1 Switch", "BST1" },
2287 { "RECMIXL", "OUT MIXL Switch", "OUT MIXL" },
2289 { "RECMIXR", "HPOR Switch", "HPOR" },
2290 { "RECMIXR", "INR Switch", "INR VOL" },
2291 { "RECMIXR", "BST2 Switch", "BST2" },
2292 { "RECMIXR", "BST1 Switch", "BST1" },
2293 { "RECMIXR", "OUT MIXR Switch", "OUT MIXR" },
2295 { "ADC L", NULL
, "RECMIXL" },
2296 { "ADC L", NULL
, "ADC L power" },
2297 { "ADC R", NULL
, "RECMIXR" },
2298 { "ADC R", NULL
, "ADC R power" },
2300 {"DMIC L1", NULL
, "DMIC CLK"},
2301 {"DMIC L1", NULL
, "DMIC1 Power"},
2302 {"DMIC R1", NULL
, "DMIC CLK"},
2303 {"DMIC R1", NULL
, "DMIC1 Power"},
2304 {"DMIC L2", NULL
, "DMIC CLK"},
2305 {"DMIC L2", NULL
, "DMIC2 Power"},
2306 {"DMIC R2", NULL
, "DMIC CLK"},
2307 {"DMIC R2", NULL
, "DMIC2 Power"},
2309 { "Stereo1 DMIC Mux", "DMIC1", "DMIC1" },
2310 { "Stereo1 DMIC Mux", "DMIC2", "DMIC2" },
2311 { "Stereo1 DMIC Mux", NULL
, "DMIC STO1 ASRC" },
2313 { "Mono DMIC L Mux", "DMIC1", "DMIC L1" },
2314 { "Mono DMIC L Mux", "DMIC2", "DMIC L2" },
2315 { "Mono DMIC L Mux", NULL
, "DMIC MONO L ASRC" },
2317 { "Mono DMIC R Mux", "DMIC1", "DMIC R1" },
2318 { "Mono DMIC R Mux", "DMIC2", "DMIC R2" },
2319 { "Mono DMIC R Mux", NULL
, "DMIC MONO R ASRC" },
2321 { "Stereo1 ADC L2 Mux", "DMIC", "Stereo1 DMIC Mux" },
2322 { "Stereo1 ADC L2 Mux", "DAC MIX", "DAC MIXL" },
2323 { "Stereo1 ADC L1 Mux", "ADC", "ADC L" },
2324 { "Stereo1 ADC L1 Mux", "DAC MIX", "DAC MIXL" },
2326 { "Stereo1 ADC R1 Mux", "ADC", "ADC R" },
2327 { "Stereo1 ADC R1 Mux", "DAC MIX", "DAC MIXR" },
2328 { "Stereo1 ADC R2 Mux", "DMIC", "Stereo1 DMIC Mux" },
2329 { "Stereo1 ADC R2 Mux", "DAC MIX", "DAC MIXR" },
2331 { "Mono ADC L2 Mux", "DMIC", "Mono DMIC L Mux" },
2332 { "Mono ADC L2 Mux", "Mono DAC MIXL", "Mono DAC MIXL" },
2333 { "Mono ADC L1 Mux", "Mono DAC MIXL", "Mono DAC MIXL" },
2334 { "Mono ADC L1 Mux", "ADC", "ADC L" },
2336 { "Mono ADC R1 Mux", "Mono DAC MIXR", "Mono DAC MIXR" },
2337 { "Mono ADC R1 Mux", "ADC", "ADC R" },
2338 { "Mono ADC R2 Mux", "DMIC", "Mono DMIC R Mux" },
2339 { "Mono ADC R2 Mux", "Mono DAC MIXR", "Mono DAC MIXR" },
2341 { "Sto1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux" },
2342 { "Sto1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux" },
2343 { "Sto1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux" },
2344 { "Sto1 ADC MIXR", "ADC2 Switch", "Stereo1 ADC R2 Mux" },
2346 { "Stereo1 ADC MIXL", NULL
, "Sto1 ADC MIXL" },
2347 { "Stereo1 ADC MIXL", NULL
, "adc stereo1 filter" },
2348 { "adc stereo1 filter", NULL
, "PLL1", is_sys_clk_from_pll
},
2350 { "Stereo1 ADC MIXR", NULL
, "Sto1 ADC MIXR" },
2351 { "Stereo1 ADC MIXR", NULL
, "adc stereo1 filter" },
2352 { "adc stereo1 filter", NULL
, "PLL1", is_sys_clk_from_pll
},
2354 { "Mono ADC MIXL", "ADC1 Switch", "Mono ADC L1 Mux" },
2355 { "Mono ADC MIXL", "ADC2 Switch", "Mono ADC L2 Mux" },
2356 { "Mono ADC MIXL", NULL
, "adc mono left filter" },
2357 { "adc mono left filter", NULL
, "PLL1", is_sys_clk_from_pll
},
2359 { "Mono ADC MIXR", "ADC1 Switch", "Mono ADC R1 Mux" },
2360 { "Mono ADC MIXR", "ADC2 Switch", "Mono ADC R2 Mux" },
2361 { "Mono ADC MIXR", NULL
, "adc mono right filter" },
2362 { "adc mono right filter", NULL
, "PLL1", is_sys_clk_from_pll
},
2364 { "VAD ADC Mux", "Sto1 ADC L", "Stereo1 ADC MIXL" },
2365 { "VAD ADC Mux", "Mono ADC L", "Mono ADC MIXL" },
2366 { "VAD ADC Mux", "Mono ADC R", "Mono ADC MIXR" },
2368 { "IF_ADC1", NULL
, "Stereo1 ADC MIXL" },
2369 { "IF_ADC1", NULL
, "Stereo1 ADC MIXR" },
2370 { "IF_ADC2", NULL
, "Mono ADC MIXL" },
2371 { "IF_ADC2", NULL
, "Mono ADC MIXR" },
2372 { "VAD_ADC", NULL
, "VAD ADC Mux" },
2374 { "IF2 ADC Mux", "IF_ADC1", "IF_ADC1" },
2375 { "IF2 ADC Mux", "IF_ADC2", "IF_ADC2" },
2376 { "IF2 ADC Mux", "VAD_ADC", "VAD_ADC" },
2378 { "IF1 ADC", NULL
, "I2S1" },
2379 { "IF2 ADC", NULL
, "I2S2" },
2380 { "IF2 ADC", NULL
, "IF2 ADC Mux" },
2382 { "AIF2TX", NULL
, "IF2 ADC" },
2384 { "IF1 DAC0", NULL
, "AIF1RX" },
2385 { "IF1 DAC1", NULL
, "AIF1RX" },
2386 { "IF1 DAC2", NULL
, "AIF1RX" },
2387 { "IF1 DAC3", NULL
, "AIF1RX" },
2388 { "IF2 DAC", NULL
, "AIF2RX" },
2390 { "IF1 DAC0", NULL
, "I2S1" },
2391 { "IF1 DAC1", NULL
, "I2S1" },
2392 { "IF1 DAC2", NULL
, "I2S1" },
2393 { "IF1 DAC3", NULL
, "I2S1" },
2394 { "IF2 DAC", NULL
, "I2S2" },
2396 { "IF2 DAC L", NULL
, "IF2 DAC" },
2397 { "IF2 DAC R", NULL
, "IF2 DAC" },
2399 { "DAC1 L Mux", "IF2 DAC", "IF2 DAC L" },
2400 { "DAC1 R Mux", "IF2 DAC", "IF2 DAC R" },
2402 { "DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL" },
2403 { "DAC1 MIXL", "DAC1 Switch", "DAC1 L Mux" },
2404 { "DAC1 MIXL", NULL
, "dac stereo1 filter" },
2405 { "DAC1 MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR" },
2406 { "DAC1 MIXR", "DAC1 Switch", "DAC1 R Mux" },
2407 { "DAC1 MIXR", NULL
, "dac stereo1 filter" },
2409 { "DAC L2 Mux", "IF2 DAC", "IF2 DAC L" },
2410 { "DAC L2 Mux", "Mono ADC", "Mono ADC MIXL" },
2411 { "DAC L2 Mux", "VAD_ADC", "VAD_ADC" },
2412 { "DAC L2 Volume", NULL
, "DAC L2 Mux" },
2413 { "DAC L2 Volume", NULL
, "dac mono left filter" },
2415 { "DAC R2 Mux", "IF2 DAC", "IF2 DAC R" },
2416 { "DAC R2 Mux", "Mono ADC", "Mono ADC MIXR" },
2417 { "DAC R2 Mux", "Haptic", "Haptic Generator" },
2418 { "DAC R2 Volume", NULL
, "DAC R2 Mux" },
2419 { "DAC R2 Volume", NULL
, "dac mono right filter" },
2421 { "Stereo DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" },
2422 { "Stereo DAC MIXL", "DAC R1 Switch", "DAC1 MIXR" },
2423 { "Stereo DAC MIXL", "DAC L2 Switch", "DAC L2 Volume" },
2424 { "Stereo DAC MIXL", NULL
, "dac stereo1 filter" },
2425 { "Stereo DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" },
2426 { "Stereo DAC MIXR", "DAC L1 Switch", "DAC1 MIXL" },
2427 { "Stereo DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" },
2428 { "Stereo DAC MIXR", NULL
, "dac stereo1 filter" },
2430 { "Mono DAC MIXL", "DAC L1 Switch", "DAC1 MIXL" },
2431 { "Mono DAC MIXL", "DAC L2 Switch", "DAC L2 Volume" },
2432 { "Mono DAC MIXL", "DAC R2 Switch", "DAC R2 Volume" },
2433 { "Mono DAC MIXL", NULL
, "dac mono left filter" },
2434 { "Mono DAC MIXR", "DAC R1 Switch", "DAC1 MIXR" },
2435 { "Mono DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" },
2436 { "Mono DAC MIXR", "DAC L2 Switch", "DAC L2 Volume" },
2437 { "Mono DAC MIXR", NULL
, "dac mono right filter" },
2439 { "DAC MIXL", "Sto DAC Mix L Switch", "Stereo DAC MIXL" },
2440 { "DAC MIXL", "DAC L2 Switch", "DAC L2 Volume" },
2441 { "DAC MIXL", "DAC R2 Switch", "DAC R2 Volume" },
2442 { "DAC MIXR", "Sto DAC Mix R Switch", "Stereo DAC MIXR" },
2443 { "DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" },
2444 { "DAC MIXR", "DAC L2 Switch", "DAC L2 Volume" },
2446 { "DAC L1", NULL
, "PLL1", is_sys_clk_from_pll
},
2447 { "DAC R1", NULL
, "PLL1", is_sys_clk_from_pll
},
2448 { "DAC L2", NULL
, "PLL1", is_sys_clk_from_pll
},
2449 { "DAC R2", NULL
, "PLL1", is_sys_clk_from_pll
},
2451 { "SPK MIXL", "BST1 Switch", "BST1" },
2452 { "SPK MIXL", "INL Switch", "INL VOL" },
2453 { "SPK MIXL", "DAC L1 Switch", "DAC L1" },
2454 { "SPK MIXL", "DAC L2 Switch", "DAC L2" },
2455 { "SPK MIXR", "BST2 Switch", "BST2" },
2456 { "SPK MIXR", "INR Switch", "INR VOL" },
2457 { "SPK MIXR", "DAC R1 Switch", "DAC R1" },
2458 { "SPK MIXR", "DAC R2 Switch", "DAC R2" },
2460 { "OUT MIXL", "BST1 Switch", "BST1" },
2461 { "OUT MIXL", "INL Switch", "INL VOL" },
2462 { "OUT MIXL", "DAC L2 Switch", "DAC L2" },
2463 { "OUT MIXL", "DAC L1 Switch", "DAC L1" },
2465 { "OUT MIXR", "BST2 Switch", "BST2" },
2466 { "OUT MIXR", "INR Switch", "INR VOL" },
2467 { "OUT MIXR", "DAC R2 Switch", "DAC R2" },
2468 { "OUT MIXR", "DAC R1 Switch", "DAC R1" },
2470 { "HPOVOL MIXL", "DAC1 Switch", "DAC L1" },
2471 { "HPOVOL MIXL", "DAC2 Switch", "DAC L2" },
2472 { "HPOVOL MIXL", "INL Switch", "INL VOL" },
2473 { "HPOVOL MIXL", "BST1 Switch", "BST1" },
2474 { "HPOVOL MIXL", NULL
, "HPOVOL MIXL Power" },
2475 { "HPOVOL MIXR", "DAC1 Switch", "DAC R1" },
2476 { "HPOVOL MIXR", "DAC2 Switch", "DAC R2" },
2477 { "HPOVOL MIXR", "INR Switch", "INR VOL" },
2478 { "HPOVOL MIXR", "BST2 Switch", "BST2" },
2479 { "HPOVOL MIXR", NULL
, "HPOVOL MIXR Power" },
2481 { "DAC 2", NULL
, "DAC L2" },
2482 { "DAC 2", NULL
, "DAC R2" },
2483 { "DAC 1", NULL
, "DAC L1" },
2484 { "DAC 1", NULL
, "DAC R1" },
2485 { "HPOVOL L", "Switch", "HPOVOL MIXL" },
2486 { "HPOVOL R", "Switch", "HPOVOL MIXR" },
2487 { "HPOVOL", NULL
, "HPOVOL L" },
2488 { "HPOVOL", NULL
, "HPOVOL R" },
2489 { "HPO MIX", "DAC1 Switch", "DAC 1" },
2490 { "HPO MIX", "HPVOL Switch", "HPOVOL" },
2492 { "SPKVOL L", "Switch", "SPK MIXL" },
2493 { "SPKVOL R", "Switch", "SPK MIXR" },
2495 { "SPOL MIX", "DAC R1 Switch", "DAC R1" },
2496 { "SPOL MIX", "DAC L1 Switch", "DAC L1" },
2497 { "SPOL MIX", "SPKVOL R Switch", "SPKVOL R" },
2498 { "SPOL MIX", "SPKVOL L Switch", "SPKVOL L" },
2499 { "SPOR MIX", "DAC R1 Switch", "DAC R1" },
2500 { "SPOR MIX", "SPKVOL R Switch", "SPKVOL R" },
2502 { "LOUT MIX", "DAC L1 Switch", "DAC L1" },
2503 { "LOUT MIX", "DAC R1 Switch", "DAC R1" },
2504 { "LOUT MIX", "OUTMIX L Switch", "OUT MIXL" },
2505 { "LOUT MIX", "OUTMIX R Switch", "OUT MIXR" },
2507 { "PDM1 L Mux", "Stereo DAC", "Stereo DAC MIXL" },
2508 { "PDM1 L Mux", "Mono DAC", "Mono DAC MIXL" },
2509 { "PDM1 L Mux", NULL
, "PDM1 Power" },
2510 { "PDM1 R Mux", "Stereo DAC", "Stereo DAC MIXR" },
2511 { "PDM1 R Mux", "Mono DAC", "Mono DAC MIXR" },
2512 { "PDM1 R Mux", NULL
, "PDM1 Power" },
2514 { "HP amp", NULL
, "HPO MIX" },
2515 { "HP amp", NULL
, "JD Power" },
2516 { "HP amp", NULL
, "Mic Det Power" },
2517 { "HP amp", NULL
, "LDO2" },
2518 { "HPOL", NULL
, "HP amp" },
2519 { "HPOR", NULL
, "HP amp" },
2521 { "LOUT amp", NULL
, "LOUT MIX" },
2522 { "LOUTL", NULL
, "LOUT amp" },
2523 { "LOUTR", NULL
, "LOUT amp" },
2525 { "PDM1 L", "Switch", "PDM1 L Mux" },
2526 { "PDM1 R", "Switch", "PDM1 R Mux" },
2528 { "PDM1L", NULL
, "PDM1 L" },
2529 { "PDM1R", NULL
, "PDM1 R" },
2531 { "SPK amp", NULL
, "SPOL MIX" },
2532 { "SPK amp", NULL
, "SPOR MIX" },
2533 { "SPOL", NULL
, "SPK amp" },
2534 { "SPOR", NULL
, "SPK amp" },
2537 static const struct snd_soc_dapm_route rt5650_specific_dapm_routes
[] = {
2538 { "A DAC1 L Mux", "DAC1", "DAC1 MIXL"},
2539 { "A DAC1 L Mux", "Stereo DAC Mixer", "Stereo DAC MIXL"},
2540 { "A DAC1 R Mux", "DAC1", "DAC1 MIXR"},
2541 { "A DAC1 R Mux", "Stereo DAC Mixer", "Stereo DAC MIXR"},
2543 { "A DAC2 L Mux", "Stereo DAC Mixer", "Stereo DAC MIXL"},
2544 { "A DAC2 L Mux", "Mono DAC Mixer", "Mono DAC MIXL"},
2545 { "A DAC2 R Mux", "Stereo DAC Mixer", "Stereo DAC MIXR"},
2546 { "A DAC2 R Mux", "Mono DAC Mixer", "Mono DAC MIXR"},
2548 { "DAC L1", NULL
, "A DAC1 L Mux" },
2549 { "DAC R1", NULL
, "A DAC1 R Mux" },
2550 { "DAC L2", NULL
, "A DAC2 L Mux" },
2551 { "DAC R2", NULL
, "A DAC2 R Mux" },
2553 { "RT5650 IF1 ADC1 Swap Mux", "L/R", "IF_ADC1" },
2554 { "RT5650 IF1 ADC1 Swap Mux", "R/L", "IF_ADC1" },
2555 { "RT5650 IF1 ADC1 Swap Mux", "L/L", "IF_ADC1" },
2556 { "RT5650 IF1 ADC1 Swap Mux", "R/R", "IF_ADC1" },
2558 { "RT5650 IF1 ADC2 Swap Mux", "L/R", "IF_ADC2" },
2559 { "RT5650 IF1 ADC2 Swap Mux", "R/L", "IF_ADC2" },
2560 { "RT5650 IF1 ADC2 Swap Mux", "L/L", "IF_ADC2" },
2561 { "RT5650 IF1 ADC2 Swap Mux", "R/R", "IF_ADC2" },
2563 { "RT5650 IF1 ADC3 Swap Mux", "L/R", "VAD_ADC" },
2564 { "RT5650 IF1 ADC3 Swap Mux", "R/L", "VAD_ADC" },
2565 { "RT5650 IF1 ADC3 Swap Mux", "L/L", "VAD_ADC" },
2566 { "RT5650 IF1 ADC3 Swap Mux", "R/R", "VAD_ADC" },
2568 { "IF1 ADC", NULL
, "RT5650 IF1 ADC1 Swap Mux" },
2569 { "IF1 ADC", NULL
, "RT5650 IF1 ADC2 Swap Mux" },
2570 { "IF1 ADC", NULL
, "RT5650 IF1 ADC3 Swap Mux" },
2572 { "RT5650 IF1 ADC Mux", "IF_ADC1/IF_ADC2/DAC_REF/Null", "IF1 ADC" },
2573 { "RT5650 IF1 ADC Mux", "IF_ADC1/IF_ADC2/Null/DAC_REF", "IF1 ADC" },
2574 { "RT5650 IF1 ADC Mux", "IF_ADC1/DAC_REF/IF_ADC2/Null", "IF1 ADC" },
2575 { "RT5650 IF1 ADC Mux", "IF_ADC1/DAC_REF/Null/IF_ADC2", "IF1 ADC" },
2576 { "RT5650 IF1 ADC Mux", "IF_ADC1/Null/DAC_REF/IF_ADC2", "IF1 ADC" },
2577 { "RT5650 IF1 ADC Mux", "IF_ADC1/Null/IF_ADC2/DAC_REF", "IF1 ADC" },
2579 { "RT5650 IF1 ADC Mux", "IF_ADC2/IF_ADC1/DAC_REF/Null", "IF1 ADC" },
2580 { "RT5650 IF1 ADC Mux", "IF_ADC2/IF_ADC1/Null/DAC_REF", "IF1 ADC" },
2581 { "RT5650 IF1 ADC Mux", "IF_ADC2/DAC_REF/IF_ADC1/Null", "IF1 ADC" },
2582 { "RT5650 IF1 ADC Mux", "IF_ADC2/DAC_REF/Null/IF_ADC1", "IF1 ADC" },
2583 { "RT5650 IF1 ADC Mux", "IF_ADC2/Null/DAC_REF/IF_ADC1", "IF1 ADC" },
2584 { "RT5650 IF1 ADC Mux", "IF_ADC2/Null/IF_ADC1/DAC_REF", "IF1 ADC" },
2586 { "RT5650 IF1 ADC Mux", "DAC_REF/IF_ADC1/IF_ADC2/Null", "IF1 ADC" },
2587 { "RT5650 IF1 ADC Mux", "DAC_REF/IF_ADC1/Null/IF_ADC2", "IF1 ADC" },
2588 { "RT5650 IF1 ADC Mux", "DAC_REF/IF_ADC2/IF_ADC1/Null", "IF1 ADC" },
2589 { "RT5650 IF1 ADC Mux", "DAC_REF/IF_ADC2/Null/IF_ADC1", "IF1 ADC" },
2590 { "RT5650 IF1 ADC Mux", "DAC_REF/Null/IF_ADC1/IF_ADC2", "IF1 ADC" },
2591 { "RT5650 IF1 ADC Mux", "DAC_REF/Null/IF_ADC2/IF_ADC1", "IF1 ADC" },
2593 { "RT5650 IF1 ADC Mux", "Null/IF_ADC1/IF_ADC2/DAC_REF", "IF1 ADC" },
2594 { "RT5650 IF1 ADC Mux", "Null/IF_ADC1/DAC_REF/IF_ADC2", "IF1 ADC" },
2595 { "RT5650 IF1 ADC Mux", "Null/IF_ADC2/IF_ADC1/DAC_REF", "IF1 ADC" },
2596 { "RT5650 IF1 ADC Mux", "Null/IF_ADC2/DAC_REF/IF_ADC1", "IF1 ADC" },
2597 { "RT5650 IF1 ADC Mux", "Null/DAC_REF/IF_ADC1/IF_ADC2", "IF1 ADC" },
2598 { "RT5650 IF1 ADC Mux", "Null/DAC_REF/IF_ADC2/IF_ADC1", "IF1 ADC" },
2599 { "AIF1TX", NULL
, "RT5650 IF1 ADC Mux" },
2601 { "RT5650 IF1 DAC1 L Mux", "Slot0", "IF1 DAC0" },
2602 { "RT5650 IF1 DAC1 L Mux", "Slot1", "IF1 DAC1" },
2603 { "RT5650 IF1 DAC1 L Mux", "Slot2", "IF1 DAC2" },
2604 { "RT5650 IF1 DAC1 L Mux", "Slot3", "IF1 DAC3" },
2606 { "RT5650 IF1 DAC1 R Mux", "Slot0", "IF1 DAC0" },
2607 { "RT5650 IF1 DAC1 R Mux", "Slot1", "IF1 DAC1" },
2608 { "RT5650 IF1 DAC1 R Mux", "Slot2", "IF1 DAC2" },
2609 { "RT5650 IF1 DAC1 R Mux", "Slot3", "IF1 DAC3" },
2611 { "RT5650 IF1 DAC2 L Mux", "Slot0", "IF1 DAC0" },
2612 { "RT5650 IF1 DAC2 L Mux", "Slot1", "IF1 DAC1" },
2613 { "RT5650 IF1 DAC2 L Mux", "Slot2", "IF1 DAC2" },
2614 { "RT5650 IF1 DAC2 L Mux", "Slot3", "IF1 DAC3" },
2616 { "RT5650 IF1 DAC2 R Mux", "Slot0", "IF1 DAC0" },
2617 { "RT5650 IF1 DAC2 R Mux", "Slot1", "IF1 DAC1" },
2618 { "RT5650 IF1 DAC2 R Mux", "Slot2", "IF1 DAC2" },
2619 { "RT5650 IF1 DAC2 R Mux", "Slot3", "IF1 DAC3" },
2621 { "DAC1 L Mux", "IF1 DAC", "RT5650 IF1 DAC1 L Mux" },
2622 { "DAC1 R Mux", "IF1 DAC", "RT5650 IF1 DAC1 R Mux" },
2624 { "DAC L2 Mux", "IF1 DAC", "RT5650 IF1 DAC2 L Mux" },
2625 { "DAC R2 Mux", "IF1 DAC", "RT5650 IF1 DAC2 R Mux" },
2628 static const struct snd_soc_dapm_route rt5645_specific_dapm_routes
[] = {
2629 { "DAC L1", NULL
, "Stereo DAC MIXL" },
2630 { "DAC R1", NULL
, "Stereo DAC MIXR" },
2631 { "DAC L2", NULL
, "Mono DAC MIXL" },
2632 { "DAC R2", NULL
, "Mono DAC MIXR" },
2634 { "RT5645 IF1 ADC1 Swap Mux", "L/R", "IF_ADC1" },
2635 { "RT5645 IF1 ADC1 Swap Mux", "R/L", "IF_ADC1" },
2636 { "RT5645 IF1 ADC1 Swap Mux", "L/L", "IF_ADC1" },
2637 { "RT5645 IF1 ADC1 Swap Mux", "R/R", "IF_ADC1" },
2639 { "RT5645 IF1 ADC2 Swap Mux", "L/R", "IF_ADC2" },
2640 { "RT5645 IF1 ADC2 Swap Mux", "R/L", "IF_ADC2" },
2641 { "RT5645 IF1 ADC2 Swap Mux", "L/L", "IF_ADC2" },
2642 { "RT5645 IF1 ADC2 Swap Mux", "R/R", "IF_ADC2" },
2644 { "RT5645 IF1 ADC3 Swap Mux", "L/R", "VAD_ADC" },
2645 { "RT5645 IF1 ADC3 Swap Mux", "R/L", "VAD_ADC" },
2646 { "RT5645 IF1 ADC3 Swap Mux", "L/L", "VAD_ADC" },
2647 { "RT5645 IF1 ADC3 Swap Mux", "R/R", "VAD_ADC" },
2649 { "IF1 ADC", NULL
, "RT5645 IF1 ADC1 Swap Mux" },
2650 { "IF1 ADC", NULL
, "RT5645 IF1 ADC2 Swap Mux" },
2651 { "IF1 ADC", NULL
, "RT5645 IF1 ADC3 Swap Mux" },
2653 { "RT5645 IF1 ADC Mux", "IF_ADC1/IF_ADC2/VAD_ADC", "IF1 ADC" },
2654 { "RT5645 IF1 ADC Mux", "IF_ADC2/IF_ADC1/VAD_ADC", "IF1 ADC" },
2655 { "RT5645 IF1 ADC Mux", "VAD_ADC/IF_ADC1/IF_ADC2", "IF1 ADC" },
2656 { "RT5645 IF1 ADC Mux", "VAD_ADC/IF_ADC2/IF_ADC1", "IF1 ADC" },
2657 { "AIF1TX", NULL
, "RT5645 IF1 ADC Mux" },
2659 { "RT5645 IF1 DAC1 L Mux", "Slot0", "IF1 DAC0" },
2660 { "RT5645 IF1 DAC1 L Mux", "Slot1", "IF1 DAC1" },
2661 { "RT5645 IF1 DAC1 L Mux", "Slot2", "IF1 DAC2" },
2662 { "RT5645 IF1 DAC1 L Mux", "Slot3", "IF1 DAC3" },
2664 { "RT5645 IF1 DAC1 R Mux", "Slot0", "IF1 DAC0" },
2665 { "RT5645 IF1 DAC1 R Mux", "Slot1", "IF1 DAC1" },
2666 { "RT5645 IF1 DAC1 R Mux", "Slot2", "IF1 DAC2" },
2667 { "RT5645 IF1 DAC1 R Mux", "Slot3", "IF1 DAC3" },
2669 { "RT5645 IF1 DAC2 L Mux", "Slot0", "IF1 DAC0" },
2670 { "RT5645 IF1 DAC2 L Mux", "Slot1", "IF1 DAC1" },
2671 { "RT5645 IF1 DAC2 L Mux", "Slot2", "IF1 DAC2" },
2672 { "RT5645 IF1 DAC2 L Mux", "Slot3", "IF1 DAC3" },
2674 { "RT5645 IF1 DAC2 R Mux", "Slot0", "IF1 DAC0" },
2675 { "RT5645 IF1 DAC2 R Mux", "Slot1", "IF1 DAC1" },
2676 { "RT5645 IF1 DAC2 R Mux", "Slot2", "IF1 DAC2" },
2677 { "RT5645 IF1 DAC2 R Mux", "Slot3", "IF1 DAC3" },
2679 { "DAC1 L Mux", "IF1 DAC", "RT5645 IF1 DAC1 L Mux" },
2680 { "DAC1 R Mux", "IF1 DAC", "RT5645 IF1 DAC1 R Mux" },
2682 { "DAC L2 Mux", "IF1 DAC", "RT5645 IF1 DAC2 L Mux" },
2683 { "DAC R2 Mux", "IF1 DAC", "RT5645 IF1 DAC2 R Mux" },
2686 static int rt5645_hw_params(struct snd_pcm_substream
*substream
,
2687 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
2689 struct snd_soc_codec
*codec
= dai
->codec
;
2690 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2691 unsigned int val_len
= 0, val_clk
, mask_clk
, dl_sft
;
2692 int pre_div
, bclk_ms
, frame_size
;
2694 rt5645
->lrck
[dai
->id
] = params_rate(params
);
2695 pre_div
= rl6231_get_clk_info(rt5645
->sysclk
, rt5645
->lrck
[dai
->id
]);
2697 dev_err(codec
->dev
, "Unsupported clock setting\n");
2700 frame_size
= snd_soc_params_to_frame_size(params
);
2701 if (frame_size
< 0) {
2702 dev_err(codec
->dev
, "Unsupported frame size: %d\n", frame_size
);
2706 switch (rt5645
->codec_type
) {
2707 case CODEC_TYPE_RT5650
:
2715 bclk_ms
= frame_size
> 32;
2716 rt5645
->bclk
[dai
->id
] = rt5645
->lrck
[dai
->id
] * (32 << bclk_ms
);
2718 dev_dbg(dai
->dev
, "bclk is %dHz and lrck is %dHz\n",
2719 rt5645
->bclk
[dai
->id
], rt5645
->lrck
[dai
->id
]);
2720 dev_dbg(dai
->dev
, "bclk_ms is %d and pre_div is %d for iis %d\n",
2721 bclk_ms
, pre_div
, dai
->id
);
2723 switch (params_width(params
)) {
2741 mask_clk
= RT5645_I2S_PD1_MASK
;
2742 val_clk
= pre_div
<< RT5645_I2S_PD1_SFT
;
2743 snd_soc_update_bits(codec
, RT5645_I2S1_SDP
,
2744 (0x3 << dl_sft
), (val_len
<< dl_sft
));
2745 snd_soc_update_bits(codec
, RT5645_ADDA_CLK1
, mask_clk
, val_clk
);
2748 mask_clk
= RT5645_I2S_BCLK_MS2_MASK
| RT5645_I2S_PD2_MASK
;
2749 val_clk
= bclk_ms
<< RT5645_I2S_BCLK_MS2_SFT
|
2750 pre_div
<< RT5645_I2S_PD2_SFT
;
2751 snd_soc_update_bits(codec
, RT5645_I2S2_SDP
,
2752 (0x3 << dl_sft
), (val_len
<< dl_sft
));
2753 snd_soc_update_bits(codec
, RT5645_ADDA_CLK1
, mask_clk
, val_clk
);
2756 dev_err(codec
->dev
, "Invalid dai->id: %d\n", dai
->id
);
2763 static int rt5645_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
2765 struct snd_soc_codec
*codec
= dai
->codec
;
2766 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2767 unsigned int reg_val
= 0, pol_sft
;
2769 switch (rt5645
->codec_type
) {
2770 case CODEC_TYPE_RT5650
:
2778 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
2779 case SND_SOC_DAIFMT_CBM_CFM
:
2780 rt5645
->master
[dai
->id
] = 1;
2782 case SND_SOC_DAIFMT_CBS_CFS
:
2783 reg_val
|= RT5645_I2S_MS_S
;
2784 rt5645
->master
[dai
->id
] = 0;
2790 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
2791 case SND_SOC_DAIFMT_NB_NF
:
2793 case SND_SOC_DAIFMT_IB_NF
:
2794 reg_val
|= (1 << pol_sft
);
2800 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
2801 case SND_SOC_DAIFMT_I2S
:
2803 case SND_SOC_DAIFMT_LEFT_J
:
2804 reg_val
|= RT5645_I2S_DF_LEFT
;
2806 case SND_SOC_DAIFMT_DSP_A
:
2807 reg_val
|= RT5645_I2S_DF_PCM_A
;
2809 case SND_SOC_DAIFMT_DSP_B
:
2810 reg_val
|= RT5645_I2S_DF_PCM_B
;
2817 snd_soc_update_bits(codec
, RT5645_I2S1_SDP
,
2818 RT5645_I2S_MS_MASK
| (1 << pol_sft
) |
2819 RT5645_I2S_DF_MASK
, reg_val
);
2822 snd_soc_update_bits(codec
, RT5645_I2S2_SDP
,
2823 RT5645_I2S_MS_MASK
| (1 << pol_sft
) |
2824 RT5645_I2S_DF_MASK
, reg_val
);
2827 dev_err(codec
->dev
, "Invalid dai->id: %d\n", dai
->id
);
2833 static int rt5645_set_dai_sysclk(struct snd_soc_dai
*dai
,
2834 int clk_id
, unsigned int freq
, int dir
)
2836 struct snd_soc_codec
*codec
= dai
->codec
;
2837 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2838 unsigned int reg_val
= 0;
2840 if (freq
== rt5645
->sysclk
&& clk_id
== rt5645
->sysclk_src
)
2844 case RT5645_SCLK_S_MCLK
:
2845 reg_val
|= RT5645_SCLK_SRC_MCLK
;
2847 case RT5645_SCLK_S_PLL1
:
2848 reg_val
|= RT5645_SCLK_SRC_PLL1
;
2850 case RT5645_SCLK_S_RCCLK
:
2851 reg_val
|= RT5645_SCLK_SRC_RCCLK
;
2854 dev_err(codec
->dev
, "Invalid clock id (%d)\n", clk_id
);
2857 snd_soc_update_bits(codec
, RT5645_GLB_CLK
,
2858 RT5645_SCLK_SRC_MASK
, reg_val
);
2859 rt5645
->sysclk
= freq
;
2860 rt5645
->sysclk_src
= clk_id
;
2862 dev_dbg(dai
->dev
, "Sysclk is %dHz and clock id is %d\n", freq
, clk_id
);
2867 static int rt5645_set_dai_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
2868 unsigned int freq_in
, unsigned int freq_out
)
2870 struct snd_soc_codec
*codec
= dai
->codec
;
2871 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2872 struct rl6231_pll_code pll_code
;
2875 if (source
== rt5645
->pll_src
&& freq_in
== rt5645
->pll_in
&&
2876 freq_out
== rt5645
->pll_out
)
2879 if (!freq_in
|| !freq_out
) {
2880 dev_dbg(codec
->dev
, "PLL disabled\n");
2883 rt5645
->pll_out
= 0;
2884 snd_soc_update_bits(codec
, RT5645_GLB_CLK
,
2885 RT5645_SCLK_SRC_MASK
, RT5645_SCLK_SRC_MCLK
);
2890 case RT5645_PLL1_S_MCLK
:
2891 snd_soc_update_bits(codec
, RT5645_GLB_CLK
,
2892 RT5645_PLL1_SRC_MASK
, RT5645_PLL1_SRC_MCLK
);
2894 case RT5645_PLL1_S_BCLK1
:
2895 case RT5645_PLL1_S_BCLK2
:
2898 snd_soc_update_bits(codec
, RT5645_GLB_CLK
,
2899 RT5645_PLL1_SRC_MASK
, RT5645_PLL1_SRC_BCLK1
);
2902 snd_soc_update_bits(codec
, RT5645_GLB_CLK
,
2903 RT5645_PLL1_SRC_MASK
, RT5645_PLL1_SRC_BCLK2
);
2906 dev_err(codec
->dev
, "Invalid dai->id: %d\n", dai
->id
);
2911 dev_err(codec
->dev
, "Unknown PLL source %d\n", source
);
2915 ret
= rl6231_pll_calc(freq_in
, freq_out
, &pll_code
);
2917 dev_err(codec
->dev
, "Unsupport input clock %d\n", freq_in
);
2921 dev_dbg(codec
->dev
, "bypass=%d m=%d n=%d k=%d\n",
2922 pll_code
.m_bp
, (pll_code
.m_bp
? 0 : pll_code
.m_code
),
2923 pll_code
.n_code
, pll_code
.k_code
);
2925 snd_soc_write(codec
, RT5645_PLL_CTRL1
,
2926 pll_code
.n_code
<< RT5645_PLL_N_SFT
| pll_code
.k_code
);
2927 snd_soc_write(codec
, RT5645_PLL_CTRL2
,
2928 (pll_code
.m_bp
? 0 : pll_code
.m_code
) << RT5645_PLL_M_SFT
|
2929 pll_code
.m_bp
<< RT5645_PLL_M_BP_SFT
);
2931 rt5645
->pll_in
= freq_in
;
2932 rt5645
->pll_out
= freq_out
;
2933 rt5645
->pll_src
= source
;
2938 static int rt5645_set_tdm_slot(struct snd_soc_dai
*dai
, unsigned int tx_mask
,
2939 unsigned int rx_mask
, int slots
, int slot_width
)
2941 struct snd_soc_codec
*codec
= dai
->codec
;
2942 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
2943 unsigned int i_slot_sft
, o_slot_sft
, i_width_sht
, o_width_sht
, en_sft
;
2944 unsigned int mask
, val
= 0;
2946 switch (rt5645
->codec_type
) {
2947 case CODEC_TYPE_RT5650
:
2957 i_slot_sft
= o_slot_sft
= 12;
2958 i_width_sht
= o_width_sht
= 10;
2962 if (rx_mask
|| tx_mask
) {
2963 val
|= (1 << en_sft
);
2964 if (rt5645
->codec_type
== CODEC_TYPE_RT5645
)
2965 snd_soc_update_bits(codec
, RT5645_BASS_BACK
,
2966 RT5645_G_BB_BST_MASK
, RT5645_G_BB_BST_25DB
);
2971 val
|= (1 << i_slot_sft
) | (1 << o_slot_sft
);
2974 val
|= (2 << i_slot_sft
) | (2 << o_slot_sft
);
2977 val
|= (3 << i_slot_sft
) | (3 << o_slot_sft
);
2984 switch (slot_width
) {
2986 val
|= (1 << i_width_sht
) | (1 << o_width_sht
);
2989 val
|= (2 << i_width_sht
) | (2 << o_width_sht
);
2992 val
|= (3 << i_width_sht
) | (3 << o_width_sht
);
2999 snd_soc_update_bits(codec
, RT5645_TDM_CTRL_1
, mask
, val
);
3004 static int rt5645_set_bias_level(struct snd_soc_codec
*codec
,
3005 enum snd_soc_bias_level level
)
3007 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
3010 case SND_SOC_BIAS_PREPARE
:
3011 if (SND_SOC_BIAS_STANDBY
== snd_soc_codec_get_bias_level(codec
)) {
3012 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
3013 RT5645_PWR_VREF1
| RT5645_PWR_MB
|
3014 RT5645_PWR_BG
| RT5645_PWR_VREF2
,
3015 RT5645_PWR_VREF1
| RT5645_PWR_MB
|
3016 RT5645_PWR_BG
| RT5645_PWR_VREF2
);
3018 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
3019 RT5645_PWR_FV1
| RT5645_PWR_FV2
,
3020 RT5645_PWR_FV1
| RT5645_PWR_FV2
);
3021 snd_soc_update_bits(codec
, RT5645_GEN_CTRL1
,
3022 RT5645_DIG_GATE_CTRL
, RT5645_DIG_GATE_CTRL
);
3026 case SND_SOC_BIAS_STANDBY
:
3027 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
3028 RT5645_PWR_VREF1
| RT5645_PWR_MB
|
3029 RT5645_PWR_BG
| RT5645_PWR_VREF2
,
3030 RT5645_PWR_VREF1
| RT5645_PWR_MB
|
3031 RT5645_PWR_BG
| RT5645_PWR_VREF2
);
3033 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
3034 RT5645_PWR_FV1
| RT5645_PWR_FV2
,
3035 RT5645_PWR_FV1
| RT5645_PWR_FV2
);
3036 if (snd_soc_codec_get_bias_level(codec
) == SND_SOC_BIAS_OFF
) {
3037 snd_soc_write(codec
, RT5645_DEPOP_M2
, 0x1140);
3039 if (rt5645
->en_button_func
)
3040 queue_delayed_work(system_power_efficient_wq
,
3041 &rt5645
->jack_detect_work
,
3042 msecs_to_jiffies(0));
3046 case SND_SOC_BIAS_OFF
:
3047 snd_soc_write(codec
, RT5645_DEPOP_M2
, 0x1100);
3048 if (!rt5645
->en_button_func
)
3049 snd_soc_update_bits(codec
, RT5645_GEN_CTRL1
,
3050 RT5645_DIG_GATE_CTRL
, 0);
3051 snd_soc_update_bits(codec
, RT5645_PWR_ANLG1
,
3052 RT5645_PWR_VREF1
| RT5645_PWR_MB
|
3053 RT5645_PWR_BG
| RT5645_PWR_VREF2
|
3054 RT5645_PWR_FV1
| RT5645_PWR_FV2
, 0x0);
3064 static void rt5645_enable_push_button_irq(struct snd_soc_codec
*codec
,
3067 struct snd_soc_dapm_context
*dapm
= snd_soc_codec_get_dapm(codec
);
3070 snd_soc_dapm_force_enable_pin(dapm
, "ADC L power");
3071 snd_soc_dapm_force_enable_pin(dapm
, "ADC R power");
3072 snd_soc_dapm_sync(dapm
);
3074 snd_soc_update_bits(codec
, RT5650_4BTN_IL_CMD1
, 0x3, 0x3);
3075 snd_soc_update_bits(codec
,
3076 RT5645_INT_IRQ_ST
, 0x8, 0x8);
3077 snd_soc_update_bits(codec
,
3078 RT5650_4BTN_IL_CMD2
, 0x8000, 0x8000);
3079 snd_soc_read(codec
, RT5650_4BTN_IL_CMD1
);
3080 pr_debug("%s read %x = %x\n", __func__
, RT5650_4BTN_IL_CMD1
,
3081 snd_soc_read(codec
, RT5650_4BTN_IL_CMD1
));
3083 snd_soc_update_bits(codec
, RT5650_4BTN_IL_CMD2
, 0x8000, 0x0);
3084 snd_soc_update_bits(codec
, RT5645_INT_IRQ_ST
, 0x8, 0x0);
3086 snd_soc_dapm_disable_pin(dapm
, "ADC L power");
3087 snd_soc_dapm_disable_pin(dapm
, "ADC R power");
3088 snd_soc_dapm_sync(dapm
);
3092 static int rt5645_jack_detect(struct snd_soc_codec
*codec
, int jack_insert
)
3094 struct snd_soc_dapm_context
*dapm
= snd_soc_codec_get_dapm(codec
);
3095 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
3099 regmap_write(rt5645
->regmap
, RT5645_CHARGE_PUMP
, 0x0006);
3101 /* for jack type detect */
3102 snd_soc_dapm_force_enable_pin(dapm
, "LDO2");
3103 snd_soc_dapm_force_enable_pin(dapm
, "Mic Det Power");
3104 snd_soc_dapm_sync(dapm
);
3105 if (!dapm
->card
->instantiated
) {
3106 /* Power up necessary bits for JD if dapm is
3108 regmap_update_bits(rt5645
->regmap
, RT5645_PWR_ANLG1
,
3109 RT5645_PWR_MB
| RT5645_PWR_VREF2
,
3110 RT5645_PWR_MB
| RT5645_PWR_VREF2
);
3111 regmap_update_bits(rt5645
->regmap
, RT5645_PWR_MIXER
,
3112 RT5645_PWR_LDO2
, RT5645_PWR_LDO2
);
3113 regmap_update_bits(rt5645
->regmap
, RT5645_PWR_VOL
,
3114 RT5645_PWR_MIC_DET
, RT5645_PWR_MIC_DET
);
3117 regmap_write(rt5645
->regmap
, RT5645_JD_CTRL3
, 0x00f0);
3118 regmap_update_bits(rt5645
->regmap
, RT5645_IN1_CTRL2
,
3119 RT5645_CBJ_MN_JD
, RT5645_CBJ_MN_JD
);
3120 regmap_update_bits(rt5645
->regmap
, RT5645_IN1_CTRL1
,
3121 RT5645_CBJ_BST1_EN
, RT5645_CBJ_BST1_EN
);
3123 regmap_update_bits(rt5645
->regmap
, RT5645_IN1_CTRL2
,
3124 RT5645_CBJ_MN_JD
, 0);
3127 regmap_read(rt5645
->regmap
, RT5645_IN1_CTRL3
, &val
);
3129 dev_dbg(codec
->dev
, "val = %d\n", val
);
3131 if (val
== 1 || val
== 2) {
3132 rt5645
->jack_type
= SND_JACK_HEADSET
;
3133 if (rt5645
->en_button_func
) {
3134 rt5645_enable_push_button_irq(codec
, true);
3137 snd_soc_dapm_disable_pin(dapm
, "Mic Det Power");
3138 snd_soc_dapm_sync(dapm
);
3139 rt5645
->jack_type
= SND_JACK_HEADPHONE
;
3141 if (rt5645
->pdata
.jd_invert
)
3142 regmap_update_bits(rt5645
->regmap
, RT5645_IRQ_CTRL2
,
3143 RT5645_JD_1_1_MASK
, RT5645_JD_1_1_NOR
);
3144 } else { /* jack out */
3145 rt5645
->jack_type
= 0;
3147 regmap_update_bits(rt5645
->regmap
, RT5645_HP_VOL
,
3148 RT5645_L_MUTE
| RT5645_R_MUTE
,
3149 RT5645_L_MUTE
| RT5645_R_MUTE
);
3150 regmap_update_bits(rt5645
->regmap
, RT5645_IN1_CTRL2
,
3151 RT5645_CBJ_MN_JD
, RT5645_CBJ_MN_JD
);
3152 regmap_update_bits(rt5645
->regmap
, RT5645_IN1_CTRL1
,
3153 RT5645_CBJ_BST1_EN
, 0);
3155 if (rt5645
->en_button_func
)
3156 rt5645_enable_push_button_irq(codec
, false);
3158 if (rt5645
->pdata
.jd_mode
== 0)
3159 snd_soc_dapm_disable_pin(dapm
, "LDO2");
3160 snd_soc_dapm_disable_pin(dapm
, "Mic Det Power");
3161 snd_soc_dapm_sync(dapm
);
3162 if (rt5645
->pdata
.jd_invert
)
3163 regmap_update_bits(rt5645
->regmap
, RT5645_IRQ_CTRL2
,
3164 RT5645_JD_1_1_MASK
, RT5645_JD_1_1_INV
);
3167 return rt5645
->jack_type
;
3170 static int rt5645_button_detect(struct snd_soc_codec
*codec
)
3174 val
= snd_soc_read(codec
, RT5650_4BTN_IL_CMD1
);
3175 pr_debug("val=0x%x\n", val
);
3176 btn_type
= val
& 0xfff0;
3177 snd_soc_write(codec
, RT5650_4BTN_IL_CMD1
, val
);
3182 static irqreturn_t
rt5645_irq(int irq
, void *data
);
3184 int rt5645_set_jack_detect(struct snd_soc_codec
*codec
,
3185 struct snd_soc_jack
*hp_jack
, struct snd_soc_jack
*mic_jack
,
3186 struct snd_soc_jack
*btn_jack
)
3188 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
3190 rt5645
->hp_jack
= hp_jack
;
3191 rt5645
->mic_jack
= mic_jack
;
3192 rt5645
->btn_jack
= btn_jack
;
3193 if (rt5645
->btn_jack
&& rt5645
->codec_type
== CODEC_TYPE_RT5650
) {
3194 rt5645
->en_button_func
= true;
3195 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
3196 RT5645_GP1_PIN_IRQ
, RT5645_GP1_PIN_IRQ
);
3197 regmap_update_bits(rt5645
->regmap
, RT5645_GEN_CTRL1
,
3198 RT5645_DIG_GATE_CTRL
, RT5645_DIG_GATE_CTRL
);
3200 rt5645_irq(0, rt5645
);
3204 EXPORT_SYMBOL_GPL(rt5645_set_jack_detect
);
3206 static void rt5645_jack_detect_work(struct work_struct
*work
)
3208 struct rt5645_priv
*rt5645
=
3209 container_of(work
, struct rt5645_priv
, jack_detect_work
.work
);
3210 int val
, btn_type
, gpio_state
= 0, report
= 0;
3215 switch (rt5645
->pdata
.jd_mode
) {
3216 case 0: /* Not using rt5645 JD */
3217 if (rt5645
->gpiod_hp_det
) {
3218 gpio_state
= gpiod_get_value(rt5645
->gpiod_hp_det
);
3219 dev_dbg(rt5645
->codec
->dev
, "gpio_state = %d\n",
3221 report
= rt5645_jack_detect(rt5645
->codec
, gpio_state
);
3223 snd_soc_jack_report(rt5645
->hp_jack
,
3224 report
, SND_JACK_HEADPHONE
);
3225 snd_soc_jack_report(rt5645
->mic_jack
,
3226 report
, SND_JACK_MICROPHONE
);
3228 case 1: /* 2 port */
3229 val
= snd_soc_read(rt5645
->codec
, RT5645_A_JD_CTRL1
) & 0x0070;
3231 default: /* 1 port */
3232 val
= snd_soc_read(rt5645
->codec
, RT5645_A_JD_CTRL1
) & 0x0020;
3239 case 0x30: /* 2 port */
3240 case 0x0: /* 1 port or 2 port */
3241 if (rt5645
->jack_type
== 0) {
3242 report
= rt5645_jack_detect(rt5645
->codec
, 1);
3243 /* for push button and jack out */
3247 if (snd_soc_read(rt5645
->codec
, RT5645_INT_IRQ_ST
) & 0x4) {
3248 /* button pressed */
3249 report
= SND_JACK_HEADSET
;
3250 btn_type
= rt5645_button_detect(rt5645
->codec
);
3251 /* rt5650 can report three kinds of button behavior,
3252 one click, double click and hold. However,
3253 currently we will report button pressed/released
3254 event. So all the three button behaviors are
3255 treated as button pressed. */
3260 report
|= SND_JACK_BTN_0
;
3265 report
|= SND_JACK_BTN_1
;
3270 report
|= SND_JACK_BTN_2
;
3275 report
|= SND_JACK_BTN_3
;
3277 case 0x0000: /* unpressed */
3280 dev_err(rt5645
->codec
->dev
,
3281 "Unexpected button code 0x%04x\n",
3286 if (btn_type
== 0)/* button release */
3287 report
= rt5645
->jack_type
;
3289 if (rt5645
->pdata
.jd_invert
) {
3290 mod_timer(&rt5645
->btn_check_timer
,
3291 msecs_to_jiffies(100));
3297 case 0x70: /* 2 port */
3298 case 0x10: /* 2 port */
3299 case 0x20: /* 1 port */
3301 snd_soc_update_bits(rt5645
->codec
,
3302 RT5645_INT_IRQ_ST
, 0x1, 0x0);
3303 rt5645_jack_detect(rt5645
->codec
, 0);
3309 snd_soc_jack_report(rt5645
->hp_jack
, report
, SND_JACK_HEADPHONE
);
3310 snd_soc_jack_report(rt5645
->mic_jack
, report
, SND_JACK_MICROPHONE
);
3311 if (rt5645
->en_button_func
)
3312 snd_soc_jack_report(rt5645
->btn_jack
,
3313 report
, SND_JACK_BTN_0
| SND_JACK_BTN_1
|
3314 SND_JACK_BTN_2
| SND_JACK_BTN_3
);
3317 static void rt5645_rcclock_work(struct work_struct
*work
)
3319 struct rt5645_priv
*rt5645
=
3320 container_of(work
, struct rt5645_priv
, rcclock_work
.work
);
3322 regmap_update_bits(rt5645
->regmap
, RT5645_MICBIAS
,
3323 RT5645_PWR_CLK25M_MASK
, RT5645_PWR_CLK25M_PD
);
3326 static irqreturn_t
rt5645_irq(int irq
, void *data
)
3328 struct rt5645_priv
*rt5645
= data
;
3330 queue_delayed_work(system_power_efficient_wq
,
3331 &rt5645
->jack_detect_work
, msecs_to_jiffies(250));
3336 static void rt5645_btn_check_callback(unsigned long data
)
3338 struct rt5645_priv
*rt5645
= (struct rt5645_priv
*)data
;
3340 queue_delayed_work(system_power_efficient_wq
,
3341 &rt5645
->jack_detect_work
, msecs_to_jiffies(5));
3344 static int rt5645_probe(struct snd_soc_codec
*codec
)
3346 struct snd_soc_dapm_context
*dapm
= snd_soc_codec_get_dapm(codec
);
3347 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
3349 rt5645
->codec
= codec
;
3351 switch (rt5645
->codec_type
) {
3352 case CODEC_TYPE_RT5645
:
3353 snd_soc_dapm_new_controls(dapm
,
3354 rt5645_specific_dapm_widgets
,
3355 ARRAY_SIZE(rt5645_specific_dapm_widgets
));
3356 snd_soc_dapm_add_routes(dapm
,
3357 rt5645_specific_dapm_routes
,
3358 ARRAY_SIZE(rt5645_specific_dapm_routes
));
3360 case CODEC_TYPE_RT5650
:
3361 snd_soc_dapm_new_controls(dapm
,
3362 rt5650_specific_dapm_widgets
,
3363 ARRAY_SIZE(rt5650_specific_dapm_widgets
));
3364 snd_soc_dapm_add_routes(dapm
,
3365 rt5650_specific_dapm_routes
,
3366 ARRAY_SIZE(rt5650_specific_dapm_routes
));
3370 snd_soc_codec_force_bias_level(codec
, SND_SOC_BIAS_OFF
);
3372 /* for JD function */
3373 if (rt5645
->pdata
.jd_mode
) {
3374 snd_soc_dapm_force_enable_pin(dapm
, "JD Power");
3375 snd_soc_dapm_force_enable_pin(dapm
, "LDO2");
3376 snd_soc_dapm_sync(dapm
);
3379 rt5645
->eq_param
= devm_kzalloc(codec
->dev
,
3380 RT5645_HWEQ_NUM
* sizeof(struct rt5645_eq_param_s
), GFP_KERNEL
);
3385 static int rt5645_remove(struct snd_soc_codec
*codec
)
3387 rt5645_reset(codec
);
3392 static int rt5645_suspend(struct snd_soc_codec
*codec
)
3394 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
3396 regcache_cache_only(rt5645
->regmap
, true);
3397 regcache_mark_dirty(rt5645
->regmap
);
3402 static int rt5645_resume(struct snd_soc_codec
*codec
)
3404 struct rt5645_priv
*rt5645
= snd_soc_codec_get_drvdata(codec
);
3406 regcache_cache_only(rt5645
->regmap
, false);
3407 regcache_sync(rt5645
->regmap
);
3412 #define rt5645_suspend NULL
3413 #define rt5645_resume NULL
3416 #define RT5645_STEREO_RATES SNDRV_PCM_RATE_8000_96000
3417 #define RT5645_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
3418 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
3420 static const struct snd_soc_dai_ops rt5645_aif_dai_ops
= {
3421 .hw_params
= rt5645_hw_params
,
3422 .set_fmt
= rt5645_set_dai_fmt
,
3423 .set_sysclk
= rt5645_set_dai_sysclk
,
3424 .set_tdm_slot
= rt5645_set_tdm_slot
,
3425 .set_pll
= rt5645_set_dai_pll
,
3428 static struct snd_soc_dai_driver rt5645_dai
[] = {
3430 .name
= "rt5645-aif1",
3433 .stream_name
= "AIF1 Playback",
3436 .rates
= RT5645_STEREO_RATES
,
3437 .formats
= RT5645_FORMATS
,
3440 .stream_name
= "AIF1 Capture",
3443 .rates
= RT5645_STEREO_RATES
,
3444 .formats
= RT5645_FORMATS
,
3446 .ops
= &rt5645_aif_dai_ops
,
3449 .name
= "rt5645-aif2",
3452 .stream_name
= "AIF2 Playback",
3455 .rates
= RT5645_STEREO_RATES
,
3456 .formats
= RT5645_FORMATS
,
3459 .stream_name
= "AIF2 Capture",
3462 .rates
= RT5645_STEREO_RATES
,
3463 .formats
= RT5645_FORMATS
,
3465 .ops
= &rt5645_aif_dai_ops
,
3469 static struct snd_soc_codec_driver soc_codec_dev_rt5645
= {
3470 .probe
= rt5645_probe
,
3471 .remove
= rt5645_remove
,
3472 .suspend
= rt5645_suspend
,
3473 .resume
= rt5645_resume
,
3474 .set_bias_level
= rt5645_set_bias_level
,
3475 .idle_bias_off
= true,
3476 .controls
= rt5645_snd_controls
,
3477 .num_controls
= ARRAY_SIZE(rt5645_snd_controls
),
3478 .dapm_widgets
= rt5645_dapm_widgets
,
3479 .num_dapm_widgets
= ARRAY_SIZE(rt5645_dapm_widgets
),
3480 .dapm_routes
= rt5645_dapm_routes
,
3481 .num_dapm_routes
= ARRAY_SIZE(rt5645_dapm_routes
),
3484 static const struct regmap_config rt5645_regmap
= {
3487 .use_single_rw
= true,
3488 .max_register
= RT5645_VENDOR_ID2
+ 1 + (ARRAY_SIZE(rt5645_ranges
) *
3490 .volatile_reg
= rt5645_volatile_register
,
3491 .readable_reg
= rt5645_readable_register
,
3493 .cache_type
= REGCACHE_RBTREE
,
3494 .reg_defaults
= rt5645_reg
,
3495 .num_reg_defaults
= ARRAY_SIZE(rt5645_reg
),
3496 .ranges
= rt5645_ranges
,
3497 .num_ranges
= ARRAY_SIZE(rt5645_ranges
),
3500 static const struct regmap_config rt5650_regmap
= {
3503 .use_single_rw
= true,
3504 .max_register
= RT5645_VENDOR_ID2
+ 1 + (ARRAY_SIZE(rt5645_ranges
) *
3506 .volatile_reg
= rt5645_volatile_register
,
3507 .readable_reg
= rt5645_readable_register
,
3509 .cache_type
= REGCACHE_RBTREE
,
3510 .reg_defaults
= rt5650_reg
,
3511 .num_reg_defaults
= ARRAY_SIZE(rt5650_reg
),
3512 .ranges
= rt5645_ranges
,
3513 .num_ranges
= ARRAY_SIZE(rt5645_ranges
),
3516 static const struct regmap_config temp_regmap
= {
3520 .use_single_rw
= true,
3521 .max_register
= RT5645_VENDOR_ID2
+ 1,
3522 .cache_type
= REGCACHE_NONE
,
3525 static const struct i2c_device_id rt5645_i2c_id
[] = {
3530 MODULE_DEVICE_TABLE(i2c
, rt5645_i2c_id
);
3533 static const struct acpi_device_id rt5645_acpi_match
[] = {
3538 MODULE_DEVICE_TABLE(acpi
, rt5645_acpi_match
);
3541 static struct rt5645_platform_data general_platform_data
= {
3542 .dmic1_data_pin
= RT5645_DMIC1_DISABLE
,
3543 .dmic2_data_pin
= RT5645_DMIC_DATA_IN2P
,
3547 static const struct dmi_system_id dmi_platform_intel_braswell
[] = {
3549 .ident
= "Intel Strago",
3551 DMI_MATCH(DMI_PRODUCT_NAME
, "Strago"),
3555 .ident
= "Google Chrome",
3557 DMI_MATCH(DMI_SYS_VENDOR
, "GOOGLE"),
3563 static struct rt5645_platform_data buddy_platform_data
= {
3564 .dmic1_data_pin
= RT5645_DMIC_DATA_GPIO5
,
3565 .dmic2_data_pin
= RT5645_DMIC_DATA_IN2P
,
3570 static struct dmi_system_id dmi_platform_intel_broadwell
[] = {
3572 .ident
= "Chrome Buddy",
3574 DMI_MATCH(DMI_PRODUCT_NAME
, "Buddy"),
3580 static bool rt5645_check_dp(struct device
*dev
)
3582 if (device_property_present(dev
, "realtek,in2-differential") ||
3583 device_property_present(dev
, "realtek,dmic1-data-pin") ||
3584 device_property_present(dev
, "realtek,dmic2-data-pin") ||
3585 device_property_present(dev
, "realtek,jd-mode"))
3591 static int rt5645_parse_dt(struct rt5645_priv
*rt5645
, struct device
*dev
)
3593 rt5645
->pdata
.in2_diff
= device_property_read_bool(dev
,
3594 "realtek,in2-differential");
3595 device_property_read_u32(dev
,
3596 "realtek,dmic1-data-pin", &rt5645
->pdata
.dmic1_data_pin
);
3597 device_property_read_u32(dev
,
3598 "realtek,dmic2-data-pin", &rt5645
->pdata
.dmic2_data_pin
);
3599 device_property_read_u32(dev
,
3600 "realtek,jd-mode", &rt5645
->pdata
.jd_mode
);
3605 static int rt5645_i2c_probe(struct i2c_client
*i2c
,
3606 const struct i2c_device_id
*id
)
3608 struct rt5645_platform_data
*pdata
= dev_get_platdata(&i2c
->dev
);
3609 struct rt5645_priv
*rt5645
;
3612 struct regmap
*regmap
;
3614 rt5645
= devm_kzalloc(&i2c
->dev
, sizeof(struct rt5645_priv
),
3620 i2c_set_clientdata(i2c
, rt5645
);
3623 rt5645
->pdata
= *pdata
;
3624 else if (dmi_check_system(dmi_platform_intel_broadwell
))
3625 rt5645
->pdata
= buddy_platform_data
;
3626 else if (rt5645_check_dp(&i2c
->dev
))
3627 rt5645_parse_dt(rt5645
, &i2c
->dev
);
3628 else if (dmi_check_system(dmi_platform_intel_braswell
))
3629 rt5645
->pdata
= general_platform_data
;
3631 rt5645
->gpiod_hp_det
= devm_gpiod_get_optional(&i2c
->dev
, "hp-detect",
3634 if (IS_ERR(rt5645
->gpiod_hp_det
)) {
3635 dev_err(&i2c
->dev
, "failed to initialize gpiod\n");
3636 return PTR_ERR(rt5645
->gpiod_hp_det
);
3639 for (i
= 0; i
< ARRAY_SIZE(rt5645
->supplies
); i
++)
3640 rt5645
->supplies
[i
].supply
= rt5645_supply_names
[i
];
3642 ret
= devm_regulator_bulk_get(&i2c
->dev
,
3643 ARRAY_SIZE(rt5645
->supplies
),
3646 dev_err(&i2c
->dev
, "Failed to request supplies: %d\n", ret
);
3650 ret
= regulator_bulk_enable(ARRAY_SIZE(rt5645
->supplies
),
3653 dev_err(&i2c
->dev
, "Failed to enable supplies: %d\n", ret
);
3657 regmap
= devm_regmap_init_i2c(i2c
, &temp_regmap
);
3658 if (IS_ERR(regmap
)) {
3659 ret
= PTR_ERR(regmap
);
3660 dev_err(&i2c
->dev
, "Failed to allocate temp register map: %d\n",
3664 regmap_read(regmap
, RT5645_VENDOR_ID2
, &val
);
3667 case RT5645_DEVICE_ID
:
3668 rt5645
->regmap
= devm_regmap_init_i2c(i2c
, &rt5645_regmap
);
3669 rt5645
->codec_type
= CODEC_TYPE_RT5645
;
3671 case RT5650_DEVICE_ID
:
3672 rt5645
->regmap
= devm_regmap_init_i2c(i2c
, &rt5650_regmap
);
3673 rt5645
->codec_type
= CODEC_TYPE_RT5650
;
3677 "Device with ID register %#x is not rt5645 or rt5650\n",
3683 if (IS_ERR(rt5645
->regmap
)) {
3684 ret
= PTR_ERR(rt5645
->regmap
);
3685 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
3690 regmap_write(rt5645
->regmap
, RT5645_RESET
, 0);
3692 ret
= regmap_register_patch(rt5645
->regmap
, init_list
,
3693 ARRAY_SIZE(init_list
));
3695 dev_warn(&i2c
->dev
, "Failed to apply regmap patch: %d\n", ret
);
3697 if (rt5645
->codec_type
== CODEC_TYPE_RT5650
) {
3698 ret
= regmap_register_patch(rt5645
->regmap
, rt5650_init_list
,
3699 ARRAY_SIZE(rt5650_init_list
));
3701 dev_warn(&i2c
->dev
, "Apply rt5650 patch failed: %d\n",
3705 if (rt5645
->pdata
.in2_diff
)
3706 regmap_update_bits(rt5645
->regmap
, RT5645_IN2_CTRL
,
3707 RT5645_IN_DF2
, RT5645_IN_DF2
);
3709 if (rt5645
->pdata
.dmic1_data_pin
|| rt5645
->pdata
.dmic2_data_pin
) {
3710 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
3711 RT5645_GP2_PIN_MASK
, RT5645_GP2_PIN_DMIC1_SCL
);
3713 switch (rt5645
->pdata
.dmic1_data_pin
) {
3714 case RT5645_DMIC_DATA_IN2N
:
3715 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
3716 RT5645_DMIC_1_DP_MASK
, RT5645_DMIC_1_DP_IN2N
);
3719 case RT5645_DMIC_DATA_GPIO5
:
3720 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
3721 RT5645_I2S2_DAC_PIN_MASK
, RT5645_I2S2_DAC_PIN_GPIO
);
3722 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
3723 RT5645_DMIC_1_DP_MASK
, RT5645_DMIC_1_DP_GPIO5
);
3724 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
3725 RT5645_GP5_PIN_MASK
, RT5645_GP5_PIN_DMIC1_SDA
);
3728 case RT5645_DMIC_DATA_GPIO11
:
3729 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
3730 RT5645_DMIC_1_DP_MASK
, RT5645_DMIC_1_DP_GPIO11
);
3731 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
3732 RT5645_GP11_PIN_MASK
,
3733 RT5645_GP11_PIN_DMIC1_SDA
);
3740 switch (rt5645
->pdata
.dmic2_data_pin
) {
3741 case RT5645_DMIC_DATA_IN2P
:
3742 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
3743 RT5645_DMIC_2_DP_MASK
, RT5645_DMIC_2_DP_IN2P
);
3746 case RT5645_DMIC_DATA_GPIO6
:
3747 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
3748 RT5645_DMIC_2_DP_MASK
, RT5645_DMIC_2_DP_GPIO6
);
3749 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
3750 RT5645_GP6_PIN_MASK
, RT5645_GP6_PIN_DMIC2_SDA
);
3753 case RT5645_DMIC_DATA_GPIO10
:
3754 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
3755 RT5645_DMIC_2_DP_MASK
, RT5645_DMIC_2_DP_GPIO10
);
3756 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
3757 RT5645_GP10_PIN_MASK
,
3758 RT5645_GP10_PIN_DMIC2_SDA
);
3761 case RT5645_DMIC_DATA_GPIO12
:
3762 regmap_update_bits(rt5645
->regmap
, RT5645_DMIC_CTRL1
,
3763 RT5645_DMIC_2_DP_MASK
, RT5645_DMIC_2_DP_GPIO12
);
3764 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
3765 RT5645_GP12_PIN_MASK
,
3766 RT5645_GP12_PIN_DMIC2_SDA
);
3773 if (rt5645
->pdata
.jd_mode
) {
3774 regmap_update_bits(rt5645
->regmap
, RT5645_GEN_CTRL3
,
3775 RT5645_IRQ_CLK_GATE_CTRL
,
3776 RT5645_IRQ_CLK_GATE_CTRL
);
3777 regmap_update_bits(rt5645
->regmap
, RT5645_MICBIAS
,
3778 RT5645_IRQ_CLK_INT
, RT5645_IRQ_CLK_INT
);
3779 regmap_update_bits(rt5645
->regmap
, RT5645_IRQ_CTRL2
,
3780 RT5645_IRQ_JD_1_1_EN
, RT5645_IRQ_JD_1_1_EN
);
3781 regmap_update_bits(rt5645
->regmap
, RT5645_GEN_CTRL3
,
3782 RT5645_JD_PSV_MODE
, RT5645_JD_PSV_MODE
);
3783 regmap_update_bits(rt5645
->regmap
, RT5645_HPO_MIXER
,
3784 RT5645_IRQ_PSV_MODE
, RT5645_IRQ_PSV_MODE
);
3785 regmap_update_bits(rt5645
->regmap
, RT5645_MICBIAS
,
3786 RT5645_MIC2_OVCD_EN
, RT5645_MIC2_OVCD_EN
);
3787 regmap_update_bits(rt5645
->regmap
, RT5645_GPIO_CTRL1
,
3788 RT5645_GP1_PIN_IRQ
, RT5645_GP1_PIN_IRQ
);
3789 switch (rt5645
->pdata
.jd_mode
) {
3791 regmap_update_bits(rt5645
->regmap
, RT5645_A_JD_CTRL1
,
3792 RT5645_JD1_MODE_MASK
,
3796 regmap_update_bits(rt5645
->regmap
, RT5645_A_JD_CTRL1
,
3797 RT5645_JD1_MODE_MASK
,
3801 regmap_update_bits(rt5645
->regmap
, RT5645_A_JD_CTRL1
,
3802 RT5645_JD1_MODE_MASK
,
3810 if (rt5645
->pdata
.jd_invert
) {
3811 regmap_update_bits(rt5645
->regmap
, RT5645_IRQ_CTRL2
,
3812 RT5645_JD_1_1_MASK
, RT5645_JD_1_1_INV
);
3813 setup_timer(&rt5645
->btn_check_timer
,
3814 rt5645_btn_check_callback
, (unsigned long)rt5645
);
3817 INIT_DELAYED_WORK(&rt5645
->jack_detect_work
, rt5645_jack_detect_work
);
3818 INIT_DELAYED_WORK(&rt5645
->rcclock_work
, rt5645_rcclock_work
);
3820 if (rt5645
->i2c
->irq
) {
3821 ret
= request_threaded_irq(rt5645
->i2c
->irq
, NULL
, rt5645_irq
,
3822 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
3823 | IRQF_ONESHOT
, "rt5645", rt5645
);
3825 dev_err(&i2c
->dev
, "Failed to reguest IRQ: %d\n", ret
);
3830 ret
= snd_soc_register_codec(&i2c
->dev
, &soc_codec_dev_rt5645
,
3831 rt5645_dai
, ARRAY_SIZE(rt5645_dai
));
3838 if (rt5645
->i2c
->irq
)
3839 free_irq(rt5645
->i2c
->irq
, rt5645
);
3841 regulator_bulk_disable(ARRAY_SIZE(rt5645
->supplies
), rt5645
->supplies
);
3845 static int rt5645_i2c_remove(struct i2c_client
*i2c
)
3847 struct rt5645_priv
*rt5645
= i2c_get_clientdata(i2c
);
3850 free_irq(i2c
->irq
, rt5645
);
3852 cancel_delayed_work_sync(&rt5645
->jack_detect_work
);
3853 cancel_delayed_work_sync(&rt5645
->rcclock_work
);
3855 snd_soc_unregister_codec(&i2c
->dev
);
3856 regulator_bulk_disable(ARRAY_SIZE(rt5645
->supplies
), rt5645
->supplies
);
3861 static void rt5645_i2c_shutdown(struct i2c_client
*i2c
)
3863 struct rt5645_priv
*rt5645
= i2c_get_clientdata(i2c
);
3865 regmap_update_bits(rt5645
->regmap
, RT5645_GEN_CTRL3
,
3866 RT5645_RING2_SLEEVE_GND
, RT5645_RING2_SLEEVE_GND
);
3867 regmap_update_bits(rt5645
->regmap
, RT5645_IN1_CTRL2
, RT5645_CBJ_MN_JD
,
3869 regmap_update_bits(rt5645
->regmap
, RT5645_IN1_CTRL1
, RT5645_CBJ_BST1_EN
,
3872 regmap_write(rt5645
->regmap
, RT5645_RESET
, 0);
3875 static struct i2c_driver rt5645_i2c_driver
= {
3878 .acpi_match_table
= ACPI_PTR(rt5645_acpi_match
),
3880 .probe
= rt5645_i2c_probe
,
3881 .remove
= rt5645_i2c_remove
,
3882 .shutdown
= rt5645_i2c_shutdown
,
3883 .id_table
= rt5645_i2c_id
,
3885 module_i2c_driver(rt5645_i2c_driver
);
3887 MODULE_DESCRIPTION("ASoC RT5645 driver");
3888 MODULE_AUTHOR("Bard Liao <bardliao@realtek.com>");
3889 MODULE_LICENSE("GPL v2");