1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt5663.c -- RT5663 ALSA SoC audio codec driver
5 * Copyright 2016 Realtek Semiconductor Corp.
6 * Author: Jack Yu <jack.yu@realtek.com>
8 #include <linux/module.h>
9 #include <linux/moduleparam.h>
10 #include <linux/init.h>
11 #include <linux/delay.h>
13 #include <linux/i2c.h>
14 #include <linux/platform_device.h>
15 #include <linux/spi/spi.h>
16 #include <linux/acpi.h>
17 #include <linux/regulator/consumer.h>
18 #include <linux/workqueue.h>
19 #include <sound/core.h>
20 #include <sound/pcm.h>
21 #include <sound/pcm_params.h>
22 #include <sound/jack.h>
23 #include <sound/soc.h>
24 #include <sound/soc-dapm.h>
25 #include <sound/initval.h>
26 #include <sound/tlv.h>
31 #define RT5663_DEVICE_ID_2 0x6451
32 #define RT5663_DEVICE_ID_1 0x6406
34 #define RT5663_POWER_ON_DELAY_MS 300
35 #define RT5663_SUPPLY_CURRENT_UA 500000
42 struct impedance_mapping_table
{
46 unsigned int dc_offset_l_manual
;
47 unsigned int dc_offset_r_manual
;
48 unsigned int dc_offset_l_manual_mic
;
49 unsigned int dc_offset_r_manual_mic
;
52 static const char *const rt5663_supply_names
[] = {
58 struct snd_soc_component
*component
;
59 struct rt5663_platform_data pdata
;
60 struct regmap
*regmap
;
61 struct delayed_work jack_detect_work
, jd_unplug_work
;
62 struct snd_soc_jack
*hs_jack
;
63 struct timer_list btn_check_timer
;
64 struct impedance_mapping_table
*imp_table
;
65 struct regulator_bulk_data supplies
[ARRAY_SIZE(rt5663_supply_names
)];
80 static const struct reg_sequence rt5663_patch_list
[] = {
88 static const struct reg_default rt5663_v2_reg
[] = {
490 static const struct reg_default rt5663_reg
[] = {
748 static bool rt5663_volatile_register(struct device
*dev
, unsigned int reg
)
752 case RT5663_SIL_DET_CTL
:
753 case RT5663_HP_IMP_GAIN_2
:
754 case RT5663_AD_DA_MIXER
:
755 case RT5663_FRAC_DIV_2
:
756 case RT5663_MICBIAS_1
:
757 case RT5663_ASRC_11_2
:
758 case RT5663_ADC_EQ_1
:
759 case RT5663_INT_ST_1
:
760 case RT5663_INT_ST_2
:
761 case RT5663_GPIO_STA1
:
762 case RT5663_SIN_GEN_1
:
763 case RT5663_IL_CMD_1
:
764 case RT5663_IL_CMD_5
:
765 case RT5663_IL_CMD_PWRSAV1
:
766 case RT5663_EM_JACK_TYPE_1
:
767 case RT5663_EM_JACK_TYPE_2
:
768 case RT5663_EM_JACK_TYPE_3
:
769 case RT5663_JD_CTRL2
:
770 case RT5663_VENDOR_ID
:
771 case RT5663_VENDOR_ID_1
:
772 case RT5663_VENDOR_ID_2
:
773 case RT5663_PLL_INT_REG
:
774 case RT5663_SOFT_RAMP
:
775 case RT5663_STO_DRE_1
:
776 case RT5663_STO_DRE_5
:
777 case RT5663_STO_DRE_6
:
778 case RT5663_STO_DRE_7
:
779 case RT5663_MIC_DECRO_1
:
780 case RT5663_MIC_DECRO_4
:
781 case RT5663_HP_IMP_SEN_1
:
782 case RT5663_HP_IMP_SEN_3
:
783 case RT5663_HP_IMP_SEN_4
:
784 case RT5663_HP_IMP_SEN_5
:
785 case RT5663_HP_CALIB_1_1
:
786 case RT5663_HP_CALIB_9
:
787 case RT5663_HP_CALIB_ST1
:
788 case RT5663_HP_CALIB_ST2
:
789 case RT5663_HP_CALIB_ST3
:
790 case RT5663_HP_CALIB_ST4
:
791 case RT5663_HP_CALIB_ST5
:
792 case RT5663_HP_CALIB_ST6
:
793 case RT5663_HP_CALIB_ST7
:
794 case RT5663_HP_CALIB_ST8
:
795 case RT5663_HP_CALIB_ST9
:
803 static bool rt5663_readable_register(struct device
*dev
, unsigned int reg
)
807 case RT5663_HP_OUT_EN
:
808 case RT5663_HP_LCH_DRE
:
809 case RT5663_HP_RCH_DRE
:
810 case RT5663_CALIB_BST
:
812 case RT5663_SIL_DET_CTL
:
813 case RT5663_PWR_SAV_SILDET
:
814 case RT5663_SIDETONE_CTL
:
815 case RT5663_STO1_DAC_DIG_VOL
:
816 case RT5663_STO1_ADC_DIG_VOL
:
817 case RT5663_STO1_BOOST
:
818 case RT5663_HP_IMP_GAIN_1
:
819 case RT5663_HP_IMP_GAIN_2
:
820 case RT5663_STO1_ADC_MIXER
:
821 case RT5663_AD_DA_MIXER
:
822 case RT5663_STO_DAC_MIXER
:
823 case RT5663_DIG_SIDE_MIXER
:
824 case RT5663_BYPASS_STO_DAC
:
825 case RT5663_CALIB_REC_MIX
:
826 case RT5663_PWR_DIG_1
:
827 case RT5663_PWR_DIG_2
:
828 case RT5663_PWR_ANLG_1
:
829 case RT5663_PWR_ANLG_2
:
830 case RT5663_PWR_ANLG_3
:
831 case RT5663_PWR_MIXER
:
832 case RT5663_SIG_CLK_DET
:
833 case RT5663_PRE_DIV_GATING_1
:
834 case RT5663_PRE_DIV_GATING_2
:
835 case RT5663_I2S1_SDP
:
836 case RT5663_ADDA_CLK_1
:
837 case RT5663_ADDA_RST
:
838 case RT5663_FRAC_DIV_1
:
839 case RT5663_FRAC_DIV_2
:
851 case RT5663_DUMMY_REG
:
858 case RT5663_HP_CHARGE_PUMP_1
:
859 case RT5663_HP_CHARGE_PUMP_2
:
860 case RT5663_MICBIAS_1
:
862 case RT5663_ASRC_11_2
:
863 case RT5663_DUMMY_REG_2
:
864 case RT5663_REC_PATH_GAIN
:
865 case RT5663_AUTO_1MRC_CLK
:
866 case RT5663_ADC_EQ_1
:
867 case RT5663_ADC_EQ_2
:
873 case RT5663_INT_ST_1
:
874 case RT5663_INT_ST_2
:
877 case RT5663_GPIO_STA1
:
878 case RT5663_SIN_GEN_1
:
879 case RT5663_SIN_GEN_2
:
880 case RT5663_SIN_GEN_3
:
881 case RT5663_SOF_VOL_ZC1
:
882 case RT5663_IL_CMD_1
:
883 case RT5663_IL_CMD_2
:
884 case RT5663_IL_CMD_3
:
885 case RT5663_IL_CMD_4
:
886 case RT5663_IL_CMD_5
:
887 case RT5663_IL_CMD_6
:
888 case RT5663_IL_CMD_7
:
889 case RT5663_IL_CMD_8
:
890 case RT5663_IL_CMD_PWRSAV1
:
891 case RT5663_IL_CMD_PWRSAV2
:
892 case RT5663_EM_JACK_TYPE_1
:
893 case RT5663_EM_JACK_TYPE_2
:
894 case RT5663_EM_JACK_TYPE_3
:
895 case RT5663_EM_JACK_TYPE_4
:
896 case RT5663_EM_JACK_TYPE_5
:
897 case RT5663_EM_JACK_TYPE_6
:
898 case RT5663_STO1_HPF_ADJ1
:
899 case RT5663_STO1_HPF_ADJ2
:
900 case RT5663_FAST_OFF_MICBIAS
:
901 case RT5663_JD_CTRL1
:
902 case RT5663_JD_CTRL2
:
903 case RT5663_DIG_MISC
:
904 case RT5663_VENDOR_ID
:
905 case RT5663_VENDOR_ID_1
:
906 case RT5663_VENDOR_ID_2
:
907 case RT5663_DIG_VOL_ZCD
:
908 case RT5663_ANA_BIAS_CUR_1
:
909 case RT5663_ANA_BIAS_CUR_2
:
910 case RT5663_ANA_BIAS_CUR_3
:
911 case RT5663_ANA_BIAS_CUR_4
:
912 case RT5663_ANA_BIAS_CUR_5
:
913 case RT5663_ANA_BIAS_CUR_6
:
914 case RT5663_BIAS_CUR_5
:
915 case RT5663_BIAS_CUR_6
:
916 case RT5663_BIAS_CUR_7
:
917 case RT5663_BIAS_CUR_8
:
918 case RT5663_DACREF_LDO
:
919 case RT5663_DUMMY_REG_3
:
920 case RT5663_BIAS_CUR_9
:
921 case RT5663_DUMMY_REG_4
:
922 case RT5663_VREFADJ_OP
:
923 case RT5663_VREF_RECMIX
:
924 case RT5663_CHARGE_PUMP_1
:
925 case RT5663_CHARGE_PUMP_1_2
:
926 case RT5663_CHARGE_PUMP_1_3
:
927 case RT5663_CHARGE_PUMP_2
:
928 case RT5663_DIG_IN_PIN1
:
929 case RT5663_PAD_DRV_CTL
:
930 case RT5663_PLL_INT_REG
:
931 case RT5663_CHOP_DAC_L
:
932 case RT5663_CHOP_ADC
:
933 case RT5663_CALIB_ADC
:
934 case RT5663_CHOP_DAC_R
:
935 case RT5663_DUMMY_CTL_DACLR
:
936 case RT5663_DUMMY_REG_5
:
937 case RT5663_SOFT_RAMP
:
938 case RT5663_TEST_MODE_1
:
939 case RT5663_TEST_MODE_2
:
940 case RT5663_TEST_MODE_3
:
941 case RT5663_STO_DRE_1
:
942 case RT5663_STO_DRE_2
:
943 case RT5663_STO_DRE_3
:
944 case RT5663_STO_DRE_4
:
945 case RT5663_STO_DRE_5
:
946 case RT5663_STO_DRE_6
:
947 case RT5663_STO_DRE_7
:
948 case RT5663_STO_DRE_8
:
949 case RT5663_STO_DRE_9
:
950 case RT5663_STO_DRE_10
:
951 case RT5663_MIC_DECRO_1
:
952 case RT5663_MIC_DECRO_2
:
953 case RT5663_MIC_DECRO_3
:
954 case RT5663_MIC_DECRO_4
:
955 case RT5663_MIC_DECRO_5
:
956 case RT5663_MIC_DECRO_6
:
957 case RT5663_HP_DECRO_1
:
958 case RT5663_HP_DECRO_2
:
959 case RT5663_HP_DECRO_3
:
960 case RT5663_HP_DECRO_4
:
961 case RT5663_HP_DECOUP
:
962 case RT5663_HP_IMP_SEN_MAP8
:
963 case RT5663_HP_IMP_SEN_MAP9
:
964 case RT5663_HP_IMP_SEN_MAP10
:
965 case RT5663_HP_IMP_SEN_MAP11
:
966 case RT5663_HP_IMP_SEN_1
:
967 case RT5663_HP_IMP_SEN_2
:
968 case RT5663_HP_IMP_SEN_3
:
969 case RT5663_HP_IMP_SEN_4
:
970 case RT5663_HP_IMP_SEN_5
:
971 case RT5663_HP_IMP_SEN_6
:
972 case RT5663_HP_IMP_SEN_7
:
973 case RT5663_HP_IMP_SEN_8
:
974 case RT5663_HP_IMP_SEN_9
:
975 case RT5663_HP_IMP_SEN_10
:
976 case RT5663_HP_IMP_SEN_11
:
977 case RT5663_HP_IMP_SEN_12
:
978 case RT5663_HP_IMP_SEN_13
:
979 case RT5663_HP_IMP_SEN_14
:
980 case RT5663_HP_IMP_SEN_15
:
981 case RT5663_HP_IMP_SEN_16
:
982 case RT5663_HP_IMP_SEN_17
:
983 case RT5663_HP_IMP_SEN_18
:
984 case RT5663_HP_IMP_SEN_19
:
985 case RT5663_HP_IMPSEN_DIG5
:
986 case RT5663_HP_IMPSEN_MAP1
:
987 case RT5663_HP_IMPSEN_MAP2
:
988 case RT5663_HP_IMPSEN_MAP3
:
989 case RT5663_HP_IMPSEN_MAP4
:
990 case RT5663_HP_IMPSEN_MAP5
:
991 case RT5663_HP_IMPSEN_MAP7
:
992 case RT5663_HP_LOGIC_1
:
993 case RT5663_HP_LOGIC_2
:
994 case RT5663_HP_CALIB_1
:
995 case RT5663_HP_CALIB_1_1
:
996 case RT5663_HP_CALIB_2
:
997 case RT5663_HP_CALIB_3
:
998 case RT5663_HP_CALIB_4
:
999 case RT5663_HP_CALIB_5
:
1000 case RT5663_HP_CALIB_5_1
:
1001 case RT5663_HP_CALIB_6
:
1002 case RT5663_HP_CALIB_7
:
1003 case RT5663_HP_CALIB_9
:
1004 case RT5663_HP_CALIB_10
:
1005 case RT5663_HP_CALIB_11
:
1006 case RT5663_HP_CALIB_ST1
:
1007 case RT5663_HP_CALIB_ST2
:
1008 case RT5663_HP_CALIB_ST3
:
1009 case RT5663_HP_CALIB_ST4
:
1010 case RT5663_HP_CALIB_ST5
:
1011 case RT5663_HP_CALIB_ST6
:
1012 case RT5663_HP_CALIB_ST7
:
1013 case RT5663_HP_CALIB_ST8
:
1014 case RT5663_HP_CALIB_ST9
:
1015 case RT5663_HP_AMP_DET
:
1016 case RT5663_DUMMY_REG_6
:
1017 case RT5663_HP_BIAS
:
1021 case RT5663_DUMMY_1
:
1022 case RT5663_DUMMY_2
:
1023 case RT5663_DUMMY_3
:
1025 case RT5663_ADC_LCH_LPF1_A1
:
1026 case RT5663_ADC_RCH_LPF1_A1
:
1027 case RT5663_ADC_LCH_LPF1_H0
:
1028 case RT5663_ADC_RCH_LPF1_H0
:
1029 case RT5663_ADC_LCH_BPF1_A1
:
1030 case RT5663_ADC_RCH_BPF1_A1
:
1031 case RT5663_ADC_LCH_BPF1_A2
:
1032 case RT5663_ADC_RCH_BPF1_A2
:
1033 case RT5663_ADC_LCH_BPF1_H0
:
1034 case RT5663_ADC_RCH_BPF1_H0
:
1035 case RT5663_ADC_LCH_BPF2_A1
:
1036 case RT5663_ADC_RCH_BPF2_A1
:
1037 case RT5663_ADC_LCH_BPF2_A2
:
1038 case RT5663_ADC_RCH_BPF2_A2
:
1039 case RT5663_ADC_LCH_BPF2_H0
:
1040 case RT5663_ADC_RCH_BPF2_H0
:
1041 case RT5663_ADC_LCH_BPF3_A1
:
1042 case RT5663_ADC_RCH_BPF3_A1
:
1043 case RT5663_ADC_LCH_BPF3_A2
:
1044 case RT5663_ADC_RCH_BPF3_A2
:
1045 case RT5663_ADC_LCH_BPF3_H0
:
1046 case RT5663_ADC_RCH_BPF3_H0
:
1047 case RT5663_ADC_LCH_BPF4_A1
:
1048 case RT5663_ADC_RCH_BPF4_A1
:
1049 case RT5663_ADC_LCH_BPF4_A2
:
1050 case RT5663_ADC_RCH_BPF4_A2
:
1051 case RT5663_ADC_LCH_BPF4_H0
:
1052 case RT5663_ADC_RCH_BPF4_H0
:
1053 case RT5663_ADC_LCH_HPF1_A1
:
1054 case RT5663_ADC_RCH_HPF1_A1
:
1055 case RT5663_ADC_LCH_HPF1_H0
:
1056 case RT5663_ADC_RCH_HPF1_H0
:
1057 case RT5663_ADC_EQ_PRE_VOL_L
:
1058 case RT5663_ADC_EQ_PRE_VOL_R
:
1059 case RT5663_ADC_EQ_POST_VOL_L
:
1060 case RT5663_ADC_EQ_POST_VOL_R
:
1067 static bool rt5663_v2_volatile_register(struct device
*dev
, unsigned int reg
)
1071 case RT5663_CBJ_TYPE_2
:
1072 case RT5663_PDM_OUT_CTL
:
1073 case RT5663_PDM_I2C_DATA_CTL1
:
1074 case RT5663_PDM_I2C_DATA_CTL4
:
1075 case RT5663_ALC_BK_GAIN
:
1077 case RT5663_MICBIAS_1
:
1078 case RT5663_ADC_EQ_1
:
1079 case RT5663_INT_ST_1
:
1080 case RT5663_GPIO_STA2
:
1081 case RT5663_IL_CMD_1
:
1082 case RT5663_IL_CMD_5
:
1083 case RT5663_A_JD_CTRL
:
1084 case RT5663_JD_CTRL2
:
1085 case RT5663_VENDOR_ID
:
1086 case RT5663_VENDOR_ID_1
:
1087 case RT5663_VENDOR_ID_2
:
1088 case RT5663_STO_DRE_1
:
1089 case RT5663_STO_DRE_5
:
1090 case RT5663_STO_DRE_6
:
1091 case RT5663_STO_DRE_7
:
1092 case RT5663_MONO_DYNA_6
:
1093 case RT5663_STO1_SIL_DET
:
1094 case RT5663_MONOL_SIL_DET
:
1095 case RT5663_MONOR_SIL_DET
:
1096 case RT5663_STO2_DAC_SIL
:
1097 case RT5663_MONO_AMP_CAL_ST1
:
1098 case RT5663_MONO_AMP_CAL_ST2
:
1099 case RT5663_MONO_AMP_CAL_ST3
:
1100 case RT5663_MONO_AMP_CAL_ST4
:
1101 case RT5663_HP_IMP_SEN_2
:
1102 case RT5663_HP_IMP_SEN_3
:
1103 case RT5663_HP_IMP_SEN_4
:
1104 case RT5663_HP_IMP_SEN_10
:
1105 case RT5663_HP_CALIB_1
:
1106 case RT5663_HP_CALIB_10
:
1107 case RT5663_HP_CALIB_ST1
:
1108 case RT5663_HP_CALIB_ST4
:
1109 case RT5663_HP_CALIB_ST5
:
1110 case RT5663_HP_CALIB_ST6
:
1111 case RT5663_HP_CALIB_ST7
:
1112 case RT5663_HP_CALIB_ST8
:
1113 case RT5663_HP_CALIB_ST9
:
1114 case RT5663_HP_CALIB_ST10
:
1115 case RT5663_HP_CALIB_ST11
:
1122 static bool rt5663_v2_readable_register(struct device
*dev
, unsigned int reg
)
1125 case RT5663_LOUT_CTRL
:
1126 case RT5663_HP_AMP_2
:
1127 case RT5663_MONO_OUT
:
1128 case RT5663_MONO_GAIN
:
1129 case RT5663_AEC_BST
:
1130 case RT5663_IN1_IN2
:
1131 case RT5663_IN3_IN4
:
1132 case RT5663_INL1_INR1
:
1133 case RT5663_CBJ_TYPE_2
:
1134 case RT5663_CBJ_TYPE_3
:
1135 case RT5663_CBJ_TYPE_4
:
1136 case RT5663_CBJ_TYPE_5
:
1137 case RT5663_CBJ_TYPE_8
:
1138 case RT5663_DAC3_DIG_VOL
:
1139 case RT5663_DAC3_CTRL
:
1140 case RT5663_MONO_ADC_DIG_VOL
:
1141 case RT5663_STO2_ADC_DIG_VOL
:
1142 case RT5663_MONO_ADC_BST_GAIN
:
1143 case RT5663_STO2_ADC_BST_GAIN
:
1144 case RT5663_SIDETONE_CTRL
:
1145 case RT5663_MONO1_ADC_MIXER
:
1146 case RT5663_STO2_ADC_MIXER
:
1147 case RT5663_MONO_DAC_MIXER
:
1148 case RT5663_DAC2_SRC_CTRL
:
1149 case RT5663_IF_3_4_DATA_CTL
:
1150 case RT5663_IF_5_DATA_CTL
:
1151 case RT5663_PDM_OUT_CTL
:
1152 case RT5663_PDM_I2C_DATA_CTL1
:
1153 case RT5663_PDM_I2C_DATA_CTL2
:
1154 case RT5663_PDM_I2C_DATA_CTL3
:
1155 case RT5663_PDM_I2C_DATA_CTL4
:
1156 case RT5663_RECMIX1_NEW
:
1157 case RT5663_RECMIX1L_0
:
1158 case RT5663_RECMIX1L
:
1159 case RT5663_RECMIX1R_0
:
1160 case RT5663_RECMIX1R
:
1161 case RT5663_RECMIX2_NEW
:
1162 case RT5663_RECMIX2_L_2
:
1163 case RT5663_RECMIX2_R
:
1164 case RT5663_RECMIX2_R_2
:
1165 case RT5663_CALIB_REC_LR
:
1166 case RT5663_ALC_BK_GAIN
:
1167 case RT5663_MONOMIX_GAIN
:
1168 case RT5663_MONOMIX_IN_GAIN
:
1169 case RT5663_OUT_MIXL_GAIN
:
1170 case RT5663_OUT_LMIX_IN_GAIN
:
1171 case RT5663_OUT_RMIX_IN_GAIN
:
1172 case RT5663_OUT_RMIX_IN_GAIN1
:
1173 case RT5663_LOUT_MIXER_CTRL
:
1174 case RT5663_PWR_VOL
:
1175 case RT5663_ADCDAC_RST
:
1176 case RT5663_I2S34_SDP
:
1177 case RT5663_I2S5_SDP
:
1185 case RT5663_PLL_TRK_13
:
1186 case RT5663_I2S_M_CLK_CTL
:
1187 case RT5663_FDIV_I2S34_M_CLK
:
1188 case RT5663_FDIV_I2S34_M_CLK2
:
1189 case RT5663_FDIV_I2S5_M_CLK
:
1190 case RT5663_FDIV_I2S5_M_CLK2
:
1191 case RT5663_V2_IRQ_4
:
1194 case RT5663_GPIO_STA2
:
1195 case RT5663_HP_AMP_DET1
:
1196 case RT5663_HP_AMP_DET2
:
1197 case RT5663_HP_AMP_DET3
:
1198 case RT5663_MID_BD_HP_AMP
:
1199 case RT5663_LOW_BD_HP_AMP
:
1200 case RT5663_SOF_VOL_ZC2
:
1201 case RT5663_ADC_STO2_ADJ1
:
1202 case RT5663_ADC_STO2_ADJ2
:
1203 case RT5663_A_JD_CTRL
:
1204 case RT5663_JD1_TRES_CTRL
:
1205 case RT5663_JD2_TRES_CTRL
:
1206 case RT5663_V2_JD_CTRL2
:
1207 case RT5663_DUM_REG_2
:
1208 case RT5663_DUM_REG_3
:
1209 case RT5663_VENDOR_ID
:
1210 case RT5663_VENDOR_ID_1
:
1211 case RT5663_VENDOR_ID_2
:
1212 case RT5663_DACADC_DIG_VOL2
:
1213 case RT5663_DIG_IN_PIN2
:
1214 case RT5663_PAD_DRV_CTL1
:
1215 case RT5663_SOF_RAM_DEPOP
:
1216 case RT5663_VOL_TEST
:
1217 case RT5663_TEST_MODE_4
:
1218 case RT5663_TEST_MODE_5
:
1219 case RT5663_STO_DRE_9
:
1220 case RT5663_MONO_DYNA_1
:
1221 case RT5663_MONO_DYNA_2
:
1222 case RT5663_MONO_DYNA_3
:
1223 case RT5663_MONO_DYNA_4
:
1224 case RT5663_MONO_DYNA_5
:
1225 case RT5663_MONO_DYNA_6
:
1226 case RT5663_STO1_SIL_DET
:
1227 case RT5663_MONOL_SIL_DET
:
1228 case RT5663_MONOR_SIL_DET
:
1229 case RT5663_STO2_DAC_SIL
:
1230 case RT5663_PWR_SAV_CTL1
:
1231 case RT5663_PWR_SAV_CTL2
:
1232 case RT5663_PWR_SAV_CTL3
:
1233 case RT5663_PWR_SAV_CTL4
:
1234 case RT5663_PWR_SAV_CTL5
:
1235 case RT5663_PWR_SAV_CTL6
:
1236 case RT5663_MONO_AMP_CAL1
:
1237 case RT5663_MONO_AMP_CAL2
:
1238 case RT5663_MONO_AMP_CAL3
:
1239 case RT5663_MONO_AMP_CAL4
:
1240 case RT5663_MONO_AMP_CAL5
:
1241 case RT5663_MONO_AMP_CAL6
:
1242 case RT5663_MONO_AMP_CAL7
:
1243 case RT5663_MONO_AMP_CAL_ST1
:
1244 case RT5663_MONO_AMP_CAL_ST2
:
1245 case RT5663_MONO_AMP_CAL_ST3
:
1246 case RT5663_MONO_AMP_CAL_ST4
:
1247 case RT5663_MONO_AMP_CAL_ST5
:
1248 case RT5663_V2_HP_IMP_SEN_13
:
1249 case RT5663_V2_HP_IMP_SEN_14
:
1250 case RT5663_V2_HP_IMP_SEN_6
:
1251 case RT5663_V2_HP_IMP_SEN_7
:
1252 case RT5663_V2_HP_IMP_SEN_8
:
1253 case RT5663_V2_HP_IMP_SEN_9
:
1254 case RT5663_V2_HP_IMP_SEN_10
:
1255 case RT5663_HP_LOGIC_3
:
1256 case RT5663_HP_CALIB_ST10
:
1257 case RT5663_HP_CALIB_ST11
:
1258 case RT5663_PRO_REG_TBL_4
:
1259 case RT5663_PRO_REG_TBL_5
:
1260 case RT5663_PRO_REG_TBL_6
:
1261 case RT5663_PRO_REG_TBL_7
:
1262 case RT5663_PRO_REG_TBL_8
:
1263 case RT5663_PRO_REG_TBL_9
:
1264 case RT5663_SAR_ADC_INL_1
:
1265 case RT5663_SAR_ADC_INL_2
:
1266 case RT5663_SAR_ADC_INL_3
:
1267 case RT5663_SAR_ADC_INL_4
:
1268 case RT5663_SAR_ADC_INL_5
:
1269 case RT5663_SAR_ADC_INL_6
:
1270 case RT5663_SAR_ADC_INL_7
:
1271 case RT5663_SAR_ADC_INL_8
:
1272 case RT5663_SAR_ADC_INL_9
:
1273 case RT5663_SAR_ADC_INL_10
:
1274 case RT5663_SAR_ADC_INL_11
:
1275 case RT5663_SAR_ADC_INL_12
:
1276 case RT5663_DRC_CTRL_1
:
1277 case RT5663_DRC1_CTRL_2
:
1278 case RT5663_DRC1_CTRL_3
:
1279 case RT5663_DRC1_CTRL_4
:
1280 case RT5663_DRC1_CTRL_5
:
1281 case RT5663_DRC1_CTRL_6
:
1282 case RT5663_DRC1_HD_CTRL_1
:
1283 case RT5663_DRC1_HD_CTRL_2
:
1284 case RT5663_DRC1_PRI_REG_1
:
1285 case RT5663_DRC1_PRI_REG_2
:
1286 case RT5663_DRC1_PRI_REG_3
:
1287 case RT5663_DRC1_PRI_REG_4
:
1288 case RT5663_DRC1_PRI_REG_5
:
1289 case RT5663_DRC1_PRI_REG_6
:
1290 case RT5663_DRC1_PRI_REG_7
:
1291 case RT5663_DRC1_PRI_REG_8
:
1292 case RT5663_ALC_PGA_CTL_1
:
1293 case RT5663_ALC_PGA_CTL_2
:
1294 case RT5663_ALC_PGA_CTL_3
:
1295 case RT5663_ALC_PGA_CTL_4
:
1296 case RT5663_ALC_PGA_CTL_5
:
1297 case RT5663_ALC_PGA_CTL_6
:
1298 case RT5663_ALC_PGA_CTL_7
:
1299 case RT5663_ALC_PGA_CTL_8
:
1300 case RT5663_ALC_PGA_REG_1
:
1301 case RT5663_ALC_PGA_REG_2
:
1302 case RT5663_ALC_PGA_REG_3
:
1303 case RT5663_ADC_EQ_RECOV_1
:
1304 case RT5663_ADC_EQ_RECOV_2
:
1305 case RT5663_ADC_EQ_RECOV_3
:
1306 case RT5663_ADC_EQ_RECOV_4
:
1307 case RT5663_ADC_EQ_RECOV_5
:
1308 case RT5663_ADC_EQ_RECOV_6
:
1309 case RT5663_ADC_EQ_RECOV_7
:
1310 case RT5663_ADC_EQ_RECOV_8
:
1311 case RT5663_ADC_EQ_RECOV_9
:
1312 case RT5663_ADC_EQ_RECOV_10
:
1313 case RT5663_ADC_EQ_RECOV_11
:
1314 case RT5663_ADC_EQ_RECOV_12
:
1315 case RT5663_ADC_EQ_RECOV_13
:
1316 case RT5663_VID_HIDDEN
:
1317 case RT5663_VID_CUSTOMER
:
1318 case RT5663_SCAN_MODE
:
1319 case RT5663_I2C_BYPA
:
1322 case RT5663_DEPOP_3
:
1323 case RT5663_ASRC_11_2
:
1324 case RT5663_INT_ST_2
:
1325 case RT5663_GPIO_STA1
:
1326 case RT5663_SIN_GEN_1
:
1327 case RT5663_SIN_GEN_2
:
1328 case RT5663_SIN_GEN_3
:
1329 case RT5663_IL_CMD_PWRSAV1
:
1330 case RT5663_IL_CMD_PWRSAV2
:
1331 case RT5663_EM_JACK_TYPE_1
:
1332 case RT5663_EM_JACK_TYPE_2
:
1333 case RT5663_EM_JACK_TYPE_3
:
1334 case RT5663_EM_JACK_TYPE_4
:
1335 case RT5663_FAST_OFF_MICBIAS
:
1336 case RT5663_ANA_BIAS_CUR_1
:
1337 case RT5663_ANA_BIAS_CUR_2
:
1338 case RT5663_BIAS_CUR_9
:
1339 case RT5663_DUMMY_REG_4
:
1340 case RT5663_VREF_RECMIX
:
1341 case RT5663_CHARGE_PUMP_1_2
:
1342 case RT5663_CHARGE_PUMP_1_3
:
1343 case RT5663_CHARGE_PUMP_2
:
1344 case RT5663_CHOP_DAC_R
:
1345 case RT5663_DUMMY_CTL_DACLR
:
1346 case RT5663_DUMMY_REG_5
:
1347 case RT5663_SOFT_RAMP
:
1348 case RT5663_TEST_MODE_1
:
1349 case RT5663_STO_DRE_10
:
1350 case RT5663_MIC_DECRO_1
:
1351 case RT5663_MIC_DECRO_2
:
1352 case RT5663_MIC_DECRO_3
:
1353 case RT5663_MIC_DECRO_4
:
1354 case RT5663_MIC_DECRO_5
:
1355 case RT5663_MIC_DECRO_6
:
1356 case RT5663_HP_DECRO_1
:
1357 case RT5663_HP_DECRO_2
:
1358 case RT5663_HP_DECRO_3
:
1359 case RT5663_HP_DECRO_4
:
1360 case RT5663_HP_DECOUP
:
1361 case RT5663_HP_IMPSEN_MAP4
:
1362 case RT5663_HP_IMPSEN_MAP5
:
1363 case RT5663_HP_IMPSEN_MAP7
:
1364 case RT5663_HP_CALIB_1
:
1370 return rt5663_readable_register(dev
, reg
);
1374 static const DECLARE_TLV_DB_SCALE(rt5663_hp_vol_tlv
, -2400, 150, 0);
1375 static const DECLARE_TLV_DB_SCALE(rt5663_v2_hp_vol_tlv
, -2250, 150, 0);
1376 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv
, -6525, 75, 0);
1377 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv
, -1725, 75, 0);
1379 /* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
1380 static const DECLARE_TLV_DB_RANGE(in_bst_tlv
,
1381 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
1382 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
1383 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
1384 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
1385 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
1386 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
1387 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0)
1390 /* Interface data select */
1391 static const char * const rt5663_if1_adc_data_select
[] = {
1392 "L/R", "R/L", "L/L", "R/R"
1395 static SOC_ENUM_SINGLE_DECL(rt5663_if1_adc_enum
, RT5663_TDM_2
,
1396 RT5663_DATA_SWAP_ADCDAT1_SHIFT
, rt5663_if1_adc_data_select
);
1398 static void rt5663_enable_push_button_irq(struct snd_soc_component
*component
,
1401 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
1404 snd_soc_component_update_bits(component
, RT5663_IL_CMD_6
,
1405 RT5663_EN_4BTN_INL_MASK
, RT5663_EN_4BTN_INL_EN
);
1406 /* reset in-line command */
1407 snd_soc_component_update_bits(component
, RT5663_IL_CMD_6
,
1408 RT5663_RESET_4BTN_INL_MASK
,
1409 RT5663_RESET_4BTN_INL_RESET
);
1410 snd_soc_component_update_bits(component
, RT5663_IL_CMD_6
,
1411 RT5663_RESET_4BTN_INL_MASK
,
1412 RT5663_RESET_4BTN_INL_NOR
);
1413 switch (rt5663
->codec_ver
) {
1415 snd_soc_component_update_bits(component
, RT5663_IRQ_3
,
1416 RT5663_V2_EN_IRQ_INLINE_MASK
,
1417 RT5663_V2_EN_IRQ_INLINE_NOR
);
1420 snd_soc_component_update_bits(component
, RT5663_IRQ_2
,
1421 RT5663_EN_IRQ_INLINE_MASK
,
1422 RT5663_EN_IRQ_INLINE_NOR
);
1425 dev_err(component
->dev
, "Unknown CODEC Version\n");
1428 switch (rt5663
->codec_ver
) {
1430 snd_soc_component_update_bits(component
, RT5663_IRQ_3
,
1431 RT5663_V2_EN_IRQ_INLINE_MASK
,
1432 RT5663_V2_EN_IRQ_INLINE_BYP
);
1435 snd_soc_component_update_bits(component
, RT5663_IRQ_2
,
1436 RT5663_EN_IRQ_INLINE_MASK
,
1437 RT5663_EN_IRQ_INLINE_BYP
);
1440 dev_err(component
->dev
, "Unknown CODEC Version\n");
1442 snd_soc_component_update_bits(component
, RT5663_IL_CMD_6
,
1443 RT5663_EN_4BTN_INL_MASK
, RT5663_EN_4BTN_INL_DIS
);
1444 /* reset in-line command */
1445 snd_soc_component_update_bits(component
, RT5663_IL_CMD_6
,
1446 RT5663_RESET_4BTN_INL_MASK
,
1447 RT5663_RESET_4BTN_INL_RESET
);
1448 snd_soc_component_update_bits(component
, RT5663_IL_CMD_6
,
1449 RT5663_RESET_4BTN_INL_MASK
,
1450 RT5663_RESET_4BTN_INL_NOR
);
1455 * rt5663_v2_jack_detect - Detect headset.
1456 * @component: SoC audio component device.
1457 * @jack_insert: Jack insert or not.
1459 * Detect whether is headset or not when jack inserted.
1461 * Returns detect status.
1464 static int rt5663_v2_jack_detect(struct snd_soc_component
*component
, int jack_insert
)
1466 struct snd_soc_dapm_context
*dapm
= snd_soc_component_get_dapm(component
);
1467 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
1468 int val
, i
= 0, sleep_time
[5] = {300, 150, 100, 50, 30};
1470 dev_dbg(component
->dev
, "%s jack_insert:%d\n", __func__
, jack_insert
);
1472 snd_soc_component_write(component
, RT5663_CBJ_TYPE_2
, 0x8040);
1473 snd_soc_component_write(component
, RT5663_CBJ_TYPE_3
, 0x1484);
1475 snd_soc_dapm_force_enable_pin(dapm
, "MICBIAS1");
1476 snd_soc_dapm_force_enable_pin(dapm
, "MICBIAS2");
1477 snd_soc_dapm_force_enable_pin(dapm
, "Mic Det Power");
1478 snd_soc_dapm_force_enable_pin(dapm
, "CBJ Power");
1479 snd_soc_dapm_sync(dapm
);
1480 snd_soc_component_update_bits(component
, RT5663_RC_CLK
,
1481 RT5663_DIG_1M_CLK_MASK
, RT5663_DIG_1M_CLK_EN
);
1482 snd_soc_component_update_bits(component
, RT5663_RECMIX
, 0x8, 0x8);
1485 msleep(sleep_time
[i
]);
1486 val
= snd_soc_component_read(component
, RT5663_CBJ_TYPE_2
) & 0x0003;
1487 if (val
== 0x1 || val
== 0x2 || val
== 0x3)
1489 dev_dbg(component
->dev
, "%s: MX-0011 val=%x sleep %d\n",
1490 __func__
, val
, sleep_time
[i
]);
1493 dev_dbg(component
->dev
, "%s val = %d\n", __func__
, val
);
1497 rt5663
->jack_type
= SND_JACK_HEADSET
;
1498 rt5663_enable_push_button_irq(component
, true);
1501 snd_soc_dapm_disable_pin(dapm
, "MICBIAS1");
1502 snd_soc_dapm_disable_pin(dapm
, "MICBIAS2");
1503 snd_soc_dapm_disable_pin(dapm
, "Mic Det Power");
1504 snd_soc_dapm_disable_pin(dapm
, "CBJ Power");
1505 snd_soc_dapm_sync(dapm
);
1506 rt5663
->jack_type
= SND_JACK_HEADPHONE
;
1510 snd_soc_component_update_bits(component
, RT5663_RECMIX
, 0x8, 0x0);
1512 if (rt5663
->jack_type
== SND_JACK_HEADSET
) {
1513 rt5663_enable_push_button_irq(component
, false);
1514 snd_soc_dapm_disable_pin(dapm
, "MICBIAS1");
1515 snd_soc_dapm_disable_pin(dapm
, "MICBIAS2");
1516 snd_soc_dapm_disable_pin(dapm
, "Mic Det Power");
1517 snd_soc_dapm_disable_pin(dapm
, "CBJ Power");
1518 snd_soc_dapm_sync(dapm
);
1520 rt5663
->jack_type
= 0;
1523 dev_dbg(component
->dev
, "jack_type = %d\n", rt5663
->jack_type
);
1524 return rt5663
->jack_type
;
1528 * rt5663_jack_detect - Detect headset.
1529 * @component: SoC audio component device.
1530 * @jack_insert: Jack insert or not.
1532 * Detect whether is headset or not when jack inserted.
1534 * Returns detect status.
1536 static int rt5663_jack_detect(struct snd_soc_component
*component
, int jack_insert
)
1538 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
1541 dev_dbg(component
->dev
, "%s jack_insert:%d\n", __func__
, jack_insert
);
1544 snd_soc_component_update_bits(component
, RT5663_DIG_MISC
,
1545 RT5663_DIG_GATE_CTRL_MASK
, RT5663_DIG_GATE_CTRL_EN
);
1546 snd_soc_component_update_bits(component
, RT5663_HP_CHARGE_PUMP_1
,
1547 RT5663_SI_HP_MASK
| RT5663_OSW_HP_L_MASK
|
1548 RT5663_OSW_HP_R_MASK
, RT5663_SI_HP_EN
|
1549 RT5663_OSW_HP_L_DIS
| RT5663_OSW_HP_R_DIS
);
1550 snd_soc_component_update_bits(component
, RT5663_DUMMY_1
,
1551 RT5663_EMB_CLK_MASK
| RT5663_HPA_CPL_BIAS_MASK
|
1552 RT5663_HPA_CPR_BIAS_MASK
, RT5663_EMB_CLK_EN
|
1553 RT5663_HPA_CPL_BIAS_1
| RT5663_HPA_CPR_BIAS_1
);
1554 snd_soc_component_update_bits(component
, RT5663_CBJ_1
,
1555 RT5663_INBUF_CBJ_BST1_MASK
| RT5663_CBJ_SENSE_BST1_MASK
,
1556 RT5663_INBUF_CBJ_BST1_ON
| RT5663_CBJ_SENSE_BST1_L
);
1557 snd_soc_component_update_bits(component
, RT5663_IL_CMD_2
,
1558 RT5663_PWR_MIC_DET_MASK
, RT5663_PWR_MIC_DET_ON
);
1559 /* BST1 power on for JD */
1560 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_2
,
1561 RT5663_PWR_BST1_MASK
, RT5663_PWR_BST1_ON
);
1562 snd_soc_component_update_bits(component
, RT5663_EM_JACK_TYPE_1
,
1563 RT5663_CBJ_DET_MASK
| RT5663_EXT_JD_MASK
|
1564 RT5663_POL_EXT_JD_MASK
, RT5663_CBJ_DET_EN
|
1565 RT5663_EXT_JD_EN
| RT5663_POL_EXT_JD_EN
);
1566 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_1
,
1567 RT5663_PWR_MB_MASK
| RT5663_LDO1_DVO_MASK
|
1568 RT5663_AMP_HP_MASK
, RT5663_PWR_MB
|
1569 RT5663_LDO1_DVO_0_9V
| RT5663_AMP_HP_3X
);
1570 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_1
,
1571 RT5663_PWR_VREF1_MASK
| RT5663_PWR_VREF2_MASK
|
1572 RT5663_PWR_FV1_MASK
| RT5663_PWR_FV2_MASK
,
1573 RT5663_PWR_VREF1
| RT5663_PWR_VREF2
);
1575 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_1
,
1576 RT5663_PWR_FV1_MASK
| RT5663_PWR_FV2_MASK
,
1577 RT5663_PWR_FV1
| RT5663_PWR_FV2
);
1578 snd_soc_component_update_bits(component
, RT5663_AUTO_1MRC_CLK
,
1579 RT5663_IRQ_POW_SAV_MASK
, RT5663_IRQ_POW_SAV_EN
);
1580 snd_soc_component_update_bits(component
, RT5663_IRQ_1
,
1581 RT5663_EN_IRQ_JD1_MASK
, RT5663_EN_IRQ_JD1_EN
);
1582 snd_soc_component_update_bits(component
, RT5663_EM_JACK_TYPE_1
,
1583 RT5663_EM_JD_MASK
, RT5663_EM_JD_RST
);
1584 snd_soc_component_update_bits(component
, RT5663_EM_JACK_TYPE_1
,
1585 RT5663_EM_JD_MASK
, RT5663_EM_JD_NOR
);
1588 regmap_read(rt5663
->regmap
, RT5663_INT_ST_2
, &val
);
1590 usleep_range(10000, 10005);
1599 val
= snd_soc_component_read(component
, RT5663_EM_JACK_TYPE_2
) & 0x0003;
1600 dev_dbg(component
->dev
, "%s val = %d\n", __func__
, val
);
1602 snd_soc_component_update_bits(component
, RT5663_HP_CHARGE_PUMP_1
,
1603 RT5663_OSW_HP_L_MASK
| RT5663_OSW_HP_R_MASK
,
1604 RT5663_OSW_HP_L_EN
| RT5663_OSW_HP_R_EN
);
1609 rt5663
->jack_type
= SND_JACK_HEADSET
;
1610 rt5663_enable_push_button_irq(component
, true);
1612 if (rt5663
->pdata
.impedance_sensing_num
)
1615 if (rt5663
->pdata
.dc_offset_l_manual_mic
) {
1616 regmap_write(rt5663
->regmap
, RT5663_MIC_DECRO_2
,
1617 rt5663
->pdata
.dc_offset_l_manual_mic
>>
1619 regmap_write(rt5663
->regmap
, RT5663_MIC_DECRO_3
,
1620 rt5663
->pdata
.dc_offset_l_manual_mic
&
1624 if (rt5663
->pdata
.dc_offset_r_manual_mic
) {
1625 regmap_write(rt5663
->regmap
, RT5663_MIC_DECRO_5
,
1626 rt5663
->pdata
.dc_offset_r_manual_mic
>>
1628 regmap_write(rt5663
->regmap
, RT5663_MIC_DECRO_6
,
1629 rt5663
->pdata
.dc_offset_r_manual_mic
&
1634 rt5663
->jack_type
= SND_JACK_HEADPHONE
;
1635 snd_soc_component_update_bits(component
,
1637 RT5663_PWR_MB_MASK
| RT5663_PWR_VREF1_MASK
|
1638 RT5663_PWR_VREF2_MASK
, 0);
1639 if (rt5663
->pdata
.impedance_sensing_num
)
1642 if (rt5663
->pdata
.dc_offset_l_manual
) {
1643 regmap_write(rt5663
->regmap
, RT5663_MIC_DECRO_2
,
1644 rt5663
->pdata
.dc_offset_l_manual
>> 16);
1645 regmap_write(rt5663
->regmap
, RT5663_MIC_DECRO_3
,
1646 rt5663
->pdata
.dc_offset_l_manual
&
1650 if (rt5663
->pdata
.dc_offset_r_manual
) {
1651 regmap_write(rt5663
->regmap
, RT5663_MIC_DECRO_5
,
1652 rt5663
->pdata
.dc_offset_r_manual
>> 16);
1653 regmap_write(rt5663
->regmap
, RT5663_MIC_DECRO_6
,
1654 rt5663
->pdata
.dc_offset_r_manual
&
1660 if (rt5663
->jack_type
== SND_JACK_HEADSET
)
1661 rt5663_enable_push_button_irq(component
, false);
1662 rt5663
->jack_type
= 0;
1663 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_1
,
1664 RT5663_PWR_MB_MASK
| RT5663_PWR_VREF1_MASK
|
1665 RT5663_PWR_VREF2_MASK
, 0);
1668 dev_dbg(component
->dev
, "jack_type = %d\n", rt5663
->jack_type
);
1669 return rt5663
->jack_type
;
1672 static int rt5663_impedance_sensing(struct snd_soc_component
*component
)
1674 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
1675 unsigned int value
, i
, reg84
, reg26
, reg2fa
, reg91
, reg10
, reg80
;
1677 for (i
= 0; i
< rt5663
->pdata
.impedance_sensing_num
; i
++) {
1678 if (rt5663
->imp_table
[i
].vol
== 7)
1682 if (rt5663
->jack_type
== SND_JACK_HEADSET
) {
1683 snd_soc_component_write(component
, RT5663_MIC_DECRO_2
,
1684 rt5663
->imp_table
[i
].dc_offset_l_manual_mic
>> 16);
1685 snd_soc_component_write(component
, RT5663_MIC_DECRO_3
,
1686 rt5663
->imp_table
[i
].dc_offset_l_manual_mic
& 0xffff);
1687 snd_soc_component_write(component
, RT5663_MIC_DECRO_5
,
1688 rt5663
->imp_table
[i
].dc_offset_r_manual_mic
>> 16);
1689 snd_soc_component_write(component
, RT5663_MIC_DECRO_6
,
1690 rt5663
->imp_table
[i
].dc_offset_r_manual_mic
& 0xffff);
1692 snd_soc_component_write(component
, RT5663_MIC_DECRO_2
,
1693 rt5663
->imp_table
[i
].dc_offset_l_manual
>> 16);
1694 snd_soc_component_write(component
, RT5663_MIC_DECRO_3
,
1695 rt5663
->imp_table
[i
].dc_offset_l_manual
& 0xffff);
1696 snd_soc_component_write(component
, RT5663_MIC_DECRO_5
,
1697 rt5663
->imp_table
[i
].dc_offset_r_manual
>> 16);
1698 snd_soc_component_write(component
, RT5663_MIC_DECRO_6
,
1699 rt5663
->imp_table
[i
].dc_offset_r_manual
& 0xffff);
1702 reg84
= snd_soc_component_read(component
, RT5663_ASRC_2
);
1703 reg26
= snd_soc_component_read(component
, RT5663_STO1_ADC_MIXER
);
1704 reg2fa
= snd_soc_component_read(component
, RT5663_DUMMY_1
);
1705 reg91
= snd_soc_component_read(component
, RT5663_HP_CHARGE_PUMP_1
);
1706 reg10
= snd_soc_component_read(component
, RT5663_RECMIX
);
1707 reg80
= snd_soc_component_read(component
, RT5663_GLB_CLK
);
1709 snd_soc_component_update_bits(component
, RT5663_STO_DRE_1
, 0x8000, 0);
1710 snd_soc_component_write(component
, RT5663_ASRC_2
, 0);
1711 snd_soc_component_write(component
, RT5663_STO1_ADC_MIXER
, 0x4040);
1712 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_1
,
1713 RT5663_PWR_VREF1_MASK
| RT5663_PWR_VREF2_MASK
|
1714 RT5663_PWR_FV1_MASK
| RT5663_PWR_FV2_MASK
,
1715 RT5663_PWR_VREF1
| RT5663_PWR_VREF2
);
1716 usleep_range(10000, 10005);
1717 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_1
,
1718 RT5663_PWR_FV1_MASK
| RT5663_PWR_FV2_MASK
,
1719 RT5663_PWR_FV1
| RT5663_PWR_FV2
);
1720 snd_soc_component_update_bits(component
, RT5663_GLB_CLK
, RT5663_SCLK_SRC_MASK
,
1721 RT5663_SCLK_SRC_RCCLK
);
1722 snd_soc_component_update_bits(component
, RT5663_RC_CLK
, RT5663_DIG_25M_CLK_MASK
,
1723 RT5663_DIG_25M_CLK_EN
);
1724 snd_soc_component_update_bits(component
, RT5663_ADDA_CLK_1
, RT5663_I2S_PD1_MASK
, 0);
1725 snd_soc_component_write(component
, RT5663_PRE_DIV_GATING_1
, 0xff00);
1726 snd_soc_component_write(component
, RT5663_PRE_DIV_GATING_2
, 0xfffc);
1727 snd_soc_component_write(component
, RT5663_HP_CHARGE_PUMP_1
, 0x1232);
1728 snd_soc_component_write(component
, RT5663_HP_LOGIC_2
, 0x0005);
1729 snd_soc_component_write(component
, RT5663_DEPOP_2
, 0x3003);
1730 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x0030, 0x0030);
1731 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x0003, 0x0003);
1732 snd_soc_component_update_bits(component
, RT5663_PWR_DIG_2
,
1733 RT5663_PWR_ADC_S1F
| RT5663_PWR_DAC_S1F
,
1734 RT5663_PWR_ADC_S1F
| RT5663_PWR_DAC_S1F
);
1735 snd_soc_component_update_bits(component
, RT5663_PWR_DIG_1
,
1736 RT5663_PWR_DAC_L1
| RT5663_PWR_DAC_R1
|
1737 RT5663_PWR_LDO_DACREF_MASK
| RT5663_PWR_ADC_L1
|
1739 RT5663_PWR_DAC_L1
| RT5663_PWR_DAC_R1
|
1740 RT5663_PWR_LDO_DACREF_ON
| RT5663_PWR_ADC_L1
|
1743 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_2
,
1744 RT5663_PWR_RECMIX1
| RT5663_PWR_RECMIX2
,
1745 RT5663_PWR_RECMIX1
| RT5663_PWR_RECMIX2
);
1747 snd_soc_component_write(component
, RT5663_HP_CHARGE_PUMP_2
, 0x1371);
1748 snd_soc_component_write(component
, RT5663_STO_DAC_MIXER
, 0);
1749 snd_soc_component_write(component
, RT5663_BYPASS_STO_DAC
, 0x000c);
1750 snd_soc_component_write(component
, RT5663_HP_BIAS
, 0xafaa);
1751 snd_soc_component_write(component
, RT5663_CHARGE_PUMP_1
, 0x2224);
1752 snd_soc_component_write(component
, RT5663_HP_OUT_EN
, 0x8088);
1753 snd_soc_component_write(component
, RT5663_CHOP_ADC
, 0x3000);
1754 snd_soc_component_write(component
, RT5663_ADDA_RST
, 0xc000);
1755 snd_soc_component_write(component
, RT5663_STO1_HPF_ADJ1
, 0x3320);
1756 snd_soc_component_write(component
, RT5663_HP_CALIB_2
, 0x00c9);
1757 snd_soc_component_write(component
, RT5663_DUMMY_1
, 0x004c);
1758 snd_soc_component_write(component
, RT5663_ANA_BIAS_CUR_1
, 0x7733);
1759 snd_soc_component_write(component
, RT5663_CHARGE_PUMP_2
, 0x7777);
1760 snd_soc_component_write(component
, RT5663_STO_DRE_9
, 0x0007);
1761 snd_soc_component_write(component
, RT5663_STO_DRE_10
, 0x0007);
1762 snd_soc_component_write(component
, RT5663_DUMMY_2
, 0x02a4);
1763 snd_soc_component_write(component
, RT5663_RECMIX
, 0x0005);
1764 snd_soc_component_write(component
, RT5663_HP_IMP_SEN_1
, 0x4334);
1765 snd_soc_component_update_bits(component
, RT5663_IRQ_3
, 0x0004, 0x0004);
1766 snd_soc_component_write(component
, RT5663_HP_LOGIC_1
, 0x2200);
1767 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x3000, 0x3000);
1768 snd_soc_component_write(component
, RT5663_HP_LOGIC_1
, 0x6200);
1770 for (i
= 0; i
< 100; i
++) {
1772 if (snd_soc_component_read(component
, RT5663_INT_ST_1
) & 0x2)
1776 value
= snd_soc_component_read(component
, RT5663_HP_IMP_SEN_4
);
1778 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x3000, 0);
1779 snd_soc_component_write(component
, RT5663_INT_ST_1
, 0);
1780 snd_soc_component_write(component
, RT5663_HP_LOGIC_1
, 0);
1781 snd_soc_component_update_bits(component
, RT5663_RC_CLK
, RT5663_DIG_25M_CLK_MASK
,
1782 RT5663_DIG_25M_CLK_DIS
);
1783 snd_soc_component_write(component
, RT5663_GLB_CLK
, reg80
);
1784 snd_soc_component_write(component
, RT5663_RECMIX
, reg10
);
1785 snd_soc_component_write(component
, RT5663_DUMMY_2
, 0x00a4);
1786 snd_soc_component_write(component
, RT5663_DUMMY_1
, reg2fa
);
1787 snd_soc_component_write(component
, RT5663_HP_CALIB_2
, 0x00c8);
1788 snd_soc_component_write(component
, RT5663_STO1_HPF_ADJ1
, 0xb320);
1789 snd_soc_component_write(component
, RT5663_ADDA_RST
, 0xe400);
1790 snd_soc_component_write(component
, RT5663_CHOP_ADC
, 0x2000);
1791 snd_soc_component_write(component
, RT5663_HP_OUT_EN
, 0x0008);
1792 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_2
,
1793 RT5663_PWR_RECMIX1
| RT5663_PWR_RECMIX2
, 0);
1794 snd_soc_component_update_bits(component
, RT5663_PWR_DIG_1
,
1795 RT5663_PWR_DAC_L1
| RT5663_PWR_DAC_R1
|
1796 RT5663_PWR_LDO_DACREF_MASK
| RT5663_PWR_ADC_L1
|
1797 RT5663_PWR_ADC_R1
, 0);
1798 snd_soc_component_update_bits(component
, RT5663_PWR_DIG_2
,
1799 RT5663_PWR_ADC_S1F
| RT5663_PWR_DAC_S1F
, 0);
1800 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x0003, 0);
1801 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x0030, 0);
1802 snd_soc_component_write(component
, RT5663_HP_LOGIC_2
, 0);
1803 snd_soc_component_write(component
, RT5663_HP_CHARGE_PUMP_1
, reg91
);
1804 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_1
,
1805 RT5663_PWR_VREF1_MASK
| RT5663_PWR_VREF2_MASK
, 0);
1806 snd_soc_component_write(component
, RT5663_STO1_ADC_MIXER
, reg26
);
1807 snd_soc_component_write(component
, RT5663_ASRC_2
, reg84
);
1809 for (i
= 0; i
< rt5663
->pdata
.impedance_sensing_num
; i
++) {
1810 if (value
>= rt5663
->imp_table
[i
].imp_min
&&
1811 value
<= rt5663
->imp_table
[i
].imp_max
)
1815 snd_soc_component_update_bits(component
, RT5663_STO_DRE_9
, RT5663_DRE_GAIN_HP_MASK
,
1816 rt5663
->imp_table
[i
].vol
);
1817 snd_soc_component_update_bits(component
, RT5663_STO_DRE_10
, RT5663_DRE_GAIN_HP_MASK
,
1818 rt5663
->imp_table
[i
].vol
);
1820 if (rt5663
->jack_type
== SND_JACK_HEADSET
) {
1821 snd_soc_component_write(component
, RT5663_MIC_DECRO_2
,
1822 rt5663
->imp_table
[i
].dc_offset_l_manual_mic
>> 16);
1823 snd_soc_component_write(component
, RT5663_MIC_DECRO_3
,
1824 rt5663
->imp_table
[i
].dc_offset_l_manual_mic
& 0xffff);
1825 snd_soc_component_write(component
, RT5663_MIC_DECRO_5
,
1826 rt5663
->imp_table
[i
].dc_offset_r_manual_mic
>> 16);
1827 snd_soc_component_write(component
, RT5663_MIC_DECRO_6
,
1828 rt5663
->imp_table
[i
].dc_offset_r_manual_mic
& 0xffff);
1830 snd_soc_component_write(component
, RT5663_MIC_DECRO_2
,
1831 rt5663
->imp_table
[i
].dc_offset_l_manual
>> 16);
1832 snd_soc_component_write(component
, RT5663_MIC_DECRO_3
,
1833 rt5663
->imp_table
[i
].dc_offset_l_manual
& 0xffff);
1834 snd_soc_component_write(component
, RT5663_MIC_DECRO_5
,
1835 rt5663
->imp_table
[i
].dc_offset_r_manual
>> 16);
1836 snd_soc_component_write(component
, RT5663_MIC_DECRO_6
,
1837 rt5663
->imp_table
[i
].dc_offset_r_manual
& 0xffff);
1843 static int rt5663_button_detect(struct snd_soc_component
*component
)
1847 val
= snd_soc_component_read(component
, RT5663_IL_CMD_5
);
1848 dev_dbg(component
->dev
, "%s: val=0x%x\n", __func__
, val
);
1849 btn_type
= val
& 0xfff0;
1850 snd_soc_component_write(component
, RT5663_IL_CMD_5
, val
);
1855 static irqreturn_t
rt5663_irq(int irq
, void *data
)
1857 struct rt5663_priv
*rt5663
= data
;
1859 dev_dbg(regmap_get_device(rt5663
->regmap
), "%s IRQ queue work\n",
1862 queue_delayed_work(system_wq
, &rt5663
->jack_detect_work
,
1863 msecs_to_jiffies(250));
1868 static int rt5663_set_jack_detect(struct snd_soc_component
*component
,
1869 struct snd_soc_jack
*hs_jack
, void *data
)
1871 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
1873 rt5663
->hs_jack
= hs_jack
;
1875 rt5663_irq(0, rt5663
);
1880 static bool rt5663_check_jd_status(struct snd_soc_component
*component
)
1882 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
1883 int val
= snd_soc_component_read(component
, RT5663_INT_ST_1
);
1885 dev_dbg(component
->dev
, "%s val=%x\n", __func__
, val
);
1888 switch (rt5663
->codec_ver
) {
1890 return !(val
& 0x2000);
1892 return !(val
& 0x1000);
1894 dev_err(component
->dev
, "Unknown CODEC Version\n");
1900 static void rt5663_jack_detect_work(struct work_struct
*work
)
1902 struct rt5663_priv
*rt5663
=
1903 container_of(work
, struct rt5663_priv
, jack_detect_work
.work
);
1904 struct snd_soc_component
*component
= rt5663
->component
;
1905 int btn_type
, report
= 0;
1910 if (rt5663_check_jd_status(component
)) {
1912 if (rt5663
->jack_type
== 0) {
1913 /* jack was out, report jack type */
1914 switch (rt5663
->codec_ver
) {
1916 report
= rt5663_v2_jack_detect(
1917 rt5663
->component
, 1);
1920 report
= rt5663_jack_detect(rt5663
->component
, 1);
1921 if (rt5663
->pdata
.impedance_sensing_num
)
1922 rt5663_impedance_sensing(rt5663
->component
);
1925 dev_err(component
->dev
, "Unknown CODEC Version\n");
1928 /* Delay the jack insert report to avoid pop noise */
1931 /* jack is already in, report button event */
1932 report
= SND_JACK_HEADSET
;
1933 btn_type
= rt5663_button_detect(rt5663
->component
);
1935 * rt5663 can report three kinds of button behavior,
1936 * one click, double click and hold. However,
1937 * currently we will report button pressed/released
1938 * event. So all the three button behaviors are
1939 * treated as button pressed.
1945 report
|= SND_JACK_BTN_0
;
1950 report
|= SND_JACK_BTN_1
;
1955 report
|= SND_JACK_BTN_2
;
1960 report
|= SND_JACK_BTN_3
;
1962 case 0x0000: /* unpressed */
1966 dev_err(rt5663
->component
->dev
,
1967 "Unexpected button code 0x%04x\n",
1971 /* button release or spurious interrput*/
1972 if (btn_type
== 0) {
1973 report
= rt5663
->jack_type
;
1974 cancel_delayed_work_sync(
1975 &rt5663
->jd_unplug_work
);
1977 queue_delayed_work(system_wq
,
1978 &rt5663
->jd_unplug_work
,
1979 msecs_to_jiffies(500));
1984 switch (rt5663
->codec_ver
) {
1986 report
= rt5663_v2_jack_detect(rt5663
->component
, 0);
1989 report
= rt5663_jack_detect(rt5663
->component
, 0);
1992 dev_err(component
->dev
, "Unknown CODEC Version\n");
1995 dev_dbg(component
->dev
, "%s jack report: 0x%04x\n", __func__
, report
);
1996 snd_soc_jack_report(rt5663
->hs_jack
, report
, SND_JACK_HEADSET
|
1997 SND_JACK_BTN_0
| SND_JACK_BTN_1
|
1998 SND_JACK_BTN_2
| SND_JACK_BTN_3
);
2001 static void rt5663_jd_unplug_work(struct work_struct
*work
)
2003 struct rt5663_priv
*rt5663
=
2004 container_of(work
, struct rt5663_priv
, jd_unplug_work
.work
);
2005 struct snd_soc_component
*component
= rt5663
->component
;
2010 if (!rt5663_check_jd_status(component
)) {
2012 switch (rt5663
->codec_ver
) {
2014 rt5663_v2_jack_detect(rt5663
->component
, 0);
2017 rt5663_jack_detect(rt5663
->component
, 0);
2020 dev_err(component
->dev
, "Unknown CODEC Version\n");
2023 snd_soc_jack_report(rt5663
->hs_jack
, 0, SND_JACK_HEADSET
|
2024 SND_JACK_BTN_0
| SND_JACK_BTN_1
|
2025 SND_JACK_BTN_2
| SND_JACK_BTN_3
);
2027 queue_delayed_work(system_wq
, &rt5663
->jd_unplug_work
,
2028 msecs_to_jiffies(500));
2032 static const struct snd_kcontrol_new rt5663_snd_controls
[] = {
2033 /* DAC Digital Volume */
2034 SOC_DOUBLE_TLV("DAC Playback Volume", RT5663_STO1_DAC_DIG_VOL
,
2035 RT5663_DAC_L1_VOL_SHIFT
+ 1, RT5663_DAC_R1_VOL_SHIFT
+ 1,
2036 87, 0, dac_vol_tlv
),
2037 /* ADC Digital Volume Control */
2038 SOC_DOUBLE("ADC Capture Switch", RT5663_STO1_ADC_DIG_VOL
,
2039 RT5663_ADC_L_MUTE_SHIFT
, RT5663_ADC_R_MUTE_SHIFT
, 1, 1),
2040 SOC_DOUBLE_TLV("ADC Capture Volume", RT5663_STO1_ADC_DIG_VOL
,
2041 RT5663_ADC_L_VOL_SHIFT
+ 1, RT5663_ADC_R_VOL_SHIFT
+ 1,
2042 63, 0, adc_vol_tlv
),
2045 static const struct snd_kcontrol_new rt5663_v2_specific_controls
[] = {
2046 /* Headphone Output Volume */
2047 SOC_DOUBLE_R_TLV("Headphone Playback Volume", RT5663_HP_LCH_DRE
,
2048 RT5663_HP_RCH_DRE
, RT5663_GAIN_HP_SHIFT
, 15, 1,
2049 rt5663_v2_hp_vol_tlv
),
2050 /* Mic Boost Volume */
2051 SOC_SINGLE_TLV("IN1 Capture Volume", RT5663_AEC_BST
,
2052 RT5663_GAIN_CBJ_SHIFT
, 8, 0, in_bst_tlv
),
2055 static const struct snd_kcontrol_new rt5663_specific_controls
[] = {
2056 /* Mic Boost Volume*/
2057 SOC_SINGLE_TLV("IN1 Capture Volume", RT5663_CBJ_2
,
2058 RT5663_GAIN_BST1_SHIFT
, 8, 0, in_bst_tlv
),
2059 /* Data Swap for Slot0/1 in ADCDAT1 */
2060 SOC_ENUM("IF1 ADC Data Swap", rt5663_if1_adc_enum
),
2063 static const struct snd_kcontrol_new rt5663_hpvol_controls
[] = {
2064 /* Headphone Output Volume */
2065 SOC_DOUBLE_R_TLV("Headphone Playback Volume", RT5663_STO_DRE_9
,
2066 RT5663_STO_DRE_10
, RT5663_DRE_GAIN_HP_SHIFT
, 23, 1,
2070 static int rt5663_is_sys_clk_from_pll(struct snd_soc_dapm_widget
*w
,
2071 struct snd_soc_dapm_widget
*sink
)
2074 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
2076 val
= snd_soc_component_read(component
, RT5663_GLB_CLK
);
2077 val
&= RT5663_SCLK_SRC_MASK
;
2078 if (val
== RT5663_SCLK_SRC_PLL1
)
2084 static int rt5663_is_using_asrc(struct snd_soc_dapm_widget
*w
,
2085 struct snd_soc_dapm_widget
*sink
)
2087 unsigned int reg
, shift
, val
;
2088 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
2089 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
2091 if (rt5663
->codec_ver
== CODEC_VER_1
) {
2093 case RT5663_ADC_STO1_ASRC_SHIFT
:
2094 reg
= RT5663_ASRC_3
;
2095 shift
= RT5663_V2_AD_STO1_TRACK_SHIFT
;
2097 case RT5663_DAC_STO1_ASRC_SHIFT
:
2098 reg
= RT5663_ASRC_2
;
2099 shift
= RT5663_DA_STO1_TRACK_SHIFT
;
2106 case RT5663_ADC_STO1_ASRC_SHIFT
:
2107 reg
= RT5663_ASRC_2
;
2108 shift
= RT5663_AD_STO1_TRACK_SHIFT
;
2110 case RT5663_DAC_STO1_ASRC_SHIFT
:
2111 reg
= RT5663_ASRC_2
;
2112 shift
= RT5663_DA_STO1_TRACK_SHIFT
;
2119 val
= (snd_soc_component_read(component
, reg
) >> shift
) & 0x7;
2127 static int rt5663_i2s_use_asrc(struct snd_soc_dapm_widget
*source
,
2128 struct snd_soc_dapm_widget
*sink
)
2130 struct snd_soc_component
*component
= snd_soc_dapm_to_component(source
->dapm
);
2131 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
2132 int da_asrc_en
, ad_asrc_en
;
2134 da_asrc_en
= (snd_soc_component_read(component
, RT5663_ASRC_2
) &
2135 RT5663_DA_STO1_TRACK_MASK
) ? 1 : 0;
2136 switch (rt5663
->codec_ver
) {
2138 ad_asrc_en
= (snd_soc_component_read(component
, RT5663_ASRC_3
) &
2139 RT5663_V2_AD_STO1_TRACK_MASK
) ? 1 : 0;
2142 ad_asrc_en
= (snd_soc_component_read(component
, RT5663_ASRC_2
) &
2143 RT5663_AD_STO1_TRACK_MASK
) ? 1 : 0;
2146 dev_err(component
->dev
, "Unknown CODEC Version\n");
2150 if (da_asrc_en
|| ad_asrc_en
)
2151 if (rt5663
->sysclk
> rt5663
->lrck
* 384)
2154 dev_err(component
->dev
, "sysclk < 384 x fs, disable i2s asrc\n");
2160 * rt5663_sel_asrc_clk_src - select ASRC clock source for a set of filters
2161 * @component: SoC audio component device.
2162 * @filter_mask: mask of filters.
2163 * @clk_src: clock source
2165 * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5663 can
2166 * only support standard 32fs or 64fs i2s format, ASRC should be enabled to
2167 * support special i2s clock format such as Intel's 100fs(100 * sampling rate).
2168 * ASRC function will track i2s clock and generate a corresponding system clock
2169 * for codec. This function provides an API to select the clock source for a
2170 * set of filters specified by the mask. And the codec driver will turn on ASRC
2171 * for these filters if ASRC is selected as their clock source.
2173 int rt5663_sel_asrc_clk_src(struct snd_soc_component
*component
,
2174 unsigned int filter_mask
, unsigned int clk_src
)
2176 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
2177 unsigned int asrc2_mask
= 0;
2178 unsigned int asrc2_value
= 0;
2179 unsigned int asrc3_mask
= 0;
2180 unsigned int asrc3_value
= 0;
2183 case RT5663_CLK_SEL_SYS
:
2184 case RT5663_CLK_SEL_I2S1_ASRC
:
2191 if (filter_mask
& RT5663_DA_STEREO_FILTER
) {
2192 asrc2_mask
|= RT5663_DA_STO1_TRACK_MASK
;
2193 asrc2_value
|= clk_src
<< RT5663_DA_STO1_TRACK_SHIFT
;
2196 if (filter_mask
& RT5663_AD_STEREO_FILTER
) {
2197 switch (rt5663
->codec_ver
) {
2199 asrc3_mask
|= RT5663_V2_AD_STO1_TRACK_MASK
;
2200 asrc3_value
|= clk_src
<< RT5663_V2_AD_STO1_TRACK_SHIFT
;
2203 asrc2_mask
|= RT5663_AD_STO1_TRACK_MASK
;
2204 asrc2_value
|= clk_src
<< RT5663_AD_STO1_TRACK_SHIFT
;
2207 dev_err(component
->dev
, "Unknown CODEC Version\n");
2212 snd_soc_component_update_bits(component
, RT5663_ASRC_2
, asrc2_mask
,
2216 snd_soc_component_update_bits(component
, RT5663_ASRC_3
, asrc3_mask
,
2221 EXPORT_SYMBOL_GPL(rt5663_sel_asrc_clk_src
);
2224 static const struct snd_kcontrol_new rt5663_recmix1l
[] = {
2225 SOC_DAPM_SINGLE("BST2 Switch", RT5663_RECMIX1L
,
2226 RT5663_RECMIX1L_BST2_SHIFT
, 1, 1),
2227 SOC_DAPM_SINGLE("BST1 CBJ Switch", RT5663_RECMIX1L
,
2228 RT5663_RECMIX1L_BST1_CBJ_SHIFT
, 1, 1),
2231 static const struct snd_kcontrol_new rt5663_recmix1r
[] = {
2232 SOC_DAPM_SINGLE("BST2 Switch", RT5663_RECMIX1R
,
2233 RT5663_RECMIX1R_BST2_SHIFT
, 1, 1),
2237 static const struct snd_kcontrol_new rt5663_sto1_adc_l_mix
[] = {
2238 SOC_DAPM_SINGLE("ADC1 Switch", RT5663_STO1_ADC_MIXER
,
2239 RT5663_M_STO1_ADC_L1_SHIFT
, 1, 1),
2240 SOC_DAPM_SINGLE("ADC2 Switch", RT5663_STO1_ADC_MIXER
,
2241 RT5663_M_STO1_ADC_L2_SHIFT
, 1, 1),
2244 static const struct snd_kcontrol_new rt5663_sto1_adc_r_mix
[] = {
2245 SOC_DAPM_SINGLE("ADC1 Switch", RT5663_STO1_ADC_MIXER
,
2246 RT5663_M_STO1_ADC_R1_SHIFT
, 1, 1),
2247 SOC_DAPM_SINGLE("ADC2 Switch", RT5663_STO1_ADC_MIXER
,
2248 RT5663_M_STO1_ADC_R2_SHIFT
, 1, 1),
2251 static const struct snd_kcontrol_new rt5663_adda_l_mix
[] = {
2252 SOC_DAPM_SINGLE("ADC L Switch", RT5663_AD_DA_MIXER
,
2253 RT5663_M_ADCMIX_L_SHIFT
, 1, 1),
2254 SOC_DAPM_SINGLE("DAC L Switch", RT5663_AD_DA_MIXER
,
2255 RT5663_M_DAC1_L_SHIFT
, 1, 1),
2258 static const struct snd_kcontrol_new rt5663_adda_r_mix
[] = {
2259 SOC_DAPM_SINGLE("ADC R Switch", RT5663_AD_DA_MIXER
,
2260 RT5663_M_ADCMIX_R_SHIFT
, 1, 1),
2261 SOC_DAPM_SINGLE("DAC R Switch", RT5663_AD_DA_MIXER
,
2262 RT5663_M_DAC1_R_SHIFT
, 1, 1),
2265 static const struct snd_kcontrol_new rt5663_sto1_dac_l_mix
[] = {
2266 SOC_DAPM_SINGLE("DAC L Switch", RT5663_STO_DAC_MIXER
,
2267 RT5663_M_DAC_L1_STO_L_SHIFT
, 1, 1),
2270 static const struct snd_kcontrol_new rt5663_sto1_dac_r_mix
[] = {
2271 SOC_DAPM_SINGLE("DAC R Switch", RT5663_STO_DAC_MIXER
,
2272 RT5663_M_DAC_R1_STO_R_SHIFT
, 1, 1),
2276 static const struct snd_kcontrol_new rt5663_hpo_switch
=
2277 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5663_HP_AMP_2
,
2278 RT5663_EN_DAC_HPO_SHIFT
, 1, 0);
2280 /* Stereo ADC source */
2281 static const char * const rt5663_sto1_adc_src
[] = {
2285 static SOC_ENUM_SINGLE_DECL(rt5663_sto1_adcl_enum
, RT5663_STO1_ADC_MIXER
,
2286 RT5663_STO1_ADC_L_SRC_SHIFT
, rt5663_sto1_adc_src
);
2288 static const struct snd_kcontrol_new rt5663_sto1_adcl_mux
=
2289 SOC_DAPM_ENUM("STO1 ADC L Mux", rt5663_sto1_adcl_enum
);
2291 static SOC_ENUM_SINGLE_DECL(rt5663_sto1_adcr_enum
, RT5663_STO1_ADC_MIXER
,
2292 RT5663_STO1_ADC_R_SRC_SHIFT
, rt5663_sto1_adc_src
);
2294 static const struct snd_kcontrol_new rt5663_sto1_adcr_mux
=
2295 SOC_DAPM_ENUM("STO1 ADC R Mux", rt5663_sto1_adcr_enum
);
2297 /* RT5663: Analog DACL1 input source */
2298 static const char * const rt5663_alg_dacl_src
[] = {
2299 "DAC L", "STO DAC MIXL"
2302 static SOC_ENUM_SINGLE_DECL(rt5663_alg_dacl_enum
, RT5663_BYPASS_STO_DAC
,
2303 RT5663_DACL1_SRC_SHIFT
, rt5663_alg_dacl_src
);
2305 static const struct snd_kcontrol_new rt5663_alg_dacl_mux
=
2306 SOC_DAPM_ENUM("DAC L Mux", rt5663_alg_dacl_enum
);
2308 /* RT5663: Analog DACR1 input source */
2309 static const char * const rt5663_alg_dacr_src
[] = {
2310 "DAC R", "STO DAC MIXR"
2313 static SOC_ENUM_SINGLE_DECL(rt5663_alg_dacr_enum
, RT5663_BYPASS_STO_DAC
,
2314 RT5663_DACR1_SRC_SHIFT
, rt5663_alg_dacr_src
);
2316 static const struct snd_kcontrol_new rt5663_alg_dacr_mux
=
2317 SOC_DAPM_ENUM("DAC R Mux", rt5663_alg_dacr_enum
);
2319 static int rt5663_hp_event(struct snd_soc_dapm_widget
*w
,
2320 struct snd_kcontrol
*kcontrol
, int event
)
2322 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
2323 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
2326 case SND_SOC_DAPM_POST_PMU
:
2327 if (rt5663
->codec_ver
== CODEC_VER_1
) {
2328 snd_soc_component_update_bits(component
, RT5663_HP_CHARGE_PUMP_1
,
2329 RT5663_SEL_PM_HP_SHIFT
, RT5663_SEL_PM_HP_HIGH
);
2330 snd_soc_component_update_bits(component
, RT5663_HP_LOGIC_2
,
2331 RT5663_HP_SIG_SRC1_MASK
,
2332 RT5663_HP_SIG_SRC1_SILENCE
);
2334 snd_soc_component_update_bits(component
,
2335 RT5663_DACREF_LDO
, 0x3e0e, 0x3a0a);
2336 snd_soc_component_write(component
, RT5663_DEPOP_2
, 0x3003);
2337 snd_soc_component_update_bits(component
, RT5663_HP_CHARGE_PUMP_1
,
2338 RT5663_OVCD_HP_MASK
, RT5663_OVCD_HP_DIS
);
2339 snd_soc_component_write(component
, RT5663_HP_CHARGE_PUMP_2
, 0x1371);
2340 snd_soc_component_write(component
, RT5663_HP_BIAS
, 0xabba);
2341 snd_soc_component_write(component
, RT5663_CHARGE_PUMP_1
, 0x2224);
2342 snd_soc_component_write(component
, RT5663_ANA_BIAS_CUR_1
, 0x7766);
2343 snd_soc_component_write(component
, RT5663_HP_BIAS
, 0xafaa);
2344 snd_soc_component_write(component
, RT5663_CHARGE_PUMP_2
, 0x7777);
2345 snd_soc_component_update_bits(component
, RT5663_STO_DRE_1
, 0x8000,
2347 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x3000,
2349 snd_soc_component_update_bits(component
,
2350 RT5663_DIG_VOL_ZCD
, 0x00c0, 0x0080);
2354 case SND_SOC_DAPM_PRE_PMD
:
2355 if (rt5663
->codec_ver
== CODEC_VER_1
) {
2356 snd_soc_component_update_bits(component
, RT5663_HP_LOGIC_2
,
2357 RT5663_HP_SIG_SRC1_MASK
,
2358 RT5663_HP_SIG_SRC1_REG
);
2360 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x3000, 0x0);
2361 snd_soc_component_update_bits(component
, RT5663_HP_CHARGE_PUMP_1
,
2362 RT5663_OVCD_HP_MASK
, RT5663_OVCD_HP_EN
);
2363 snd_soc_component_update_bits(component
,
2364 RT5663_DACREF_LDO
, 0x3e0e, 0);
2365 snd_soc_component_update_bits(component
,
2366 RT5663_DIG_VOL_ZCD
, 0x00c0, 0);
2377 static int rt5663_charge_pump_event(struct snd_soc_dapm_widget
*w
,
2378 struct snd_kcontrol
*kcontrol
, int event
)
2380 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
2381 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
2384 case SND_SOC_DAPM_PRE_PMU
:
2385 if (rt5663
->codec_ver
== CODEC_VER_0
) {
2386 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x0030,
2388 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x0003,
2393 case SND_SOC_DAPM_POST_PMD
:
2394 if (rt5663
->codec_ver
== CODEC_VER_0
) {
2395 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x0003, 0);
2396 snd_soc_component_update_bits(component
, RT5663_DEPOP_1
, 0x0030, 0);
2407 static int rt5663_bst2_power(struct snd_soc_dapm_widget
*w
,
2408 struct snd_kcontrol
*kcontrol
, int event
)
2410 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
2413 case SND_SOC_DAPM_POST_PMU
:
2414 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_2
,
2415 RT5663_PWR_BST2_MASK
| RT5663_PWR_BST2_OP_MASK
,
2416 RT5663_PWR_BST2
| RT5663_PWR_BST2_OP
);
2419 case SND_SOC_DAPM_PRE_PMD
:
2420 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_2
,
2421 RT5663_PWR_BST2_MASK
| RT5663_PWR_BST2_OP_MASK
, 0);
2431 static int rt5663_pre_div_power(struct snd_soc_dapm_widget
*w
,
2432 struct snd_kcontrol
*kcontrol
, int event
)
2434 struct snd_soc_component
*component
= snd_soc_dapm_to_component(w
->dapm
);
2437 case SND_SOC_DAPM_POST_PMU
:
2438 snd_soc_component_write(component
, RT5663_PRE_DIV_GATING_1
, 0xff00);
2439 snd_soc_component_write(component
, RT5663_PRE_DIV_GATING_2
, 0xfffc);
2442 case SND_SOC_DAPM_PRE_PMD
:
2443 snd_soc_component_write(component
, RT5663_PRE_DIV_GATING_1
, 0x0000);
2444 snd_soc_component_write(component
, RT5663_PRE_DIV_GATING_2
, 0x0000);
2454 static const struct snd_soc_dapm_widget rt5663_dapm_widgets
[] = {
2455 SND_SOC_DAPM_SUPPLY("PLL", RT5663_PWR_ANLG_3
, RT5663_PWR_PLL_SHIFT
, 0,
2459 SND_SOC_DAPM_MICBIAS("MICBIAS1", RT5663_PWR_ANLG_2
,
2460 RT5663_PWR_MB1_SHIFT
, 0),
2461 SND_SOC_DAPM_MICBIAS("MICBIAS2", RT5663_PWR_ANLG_2
,
2462 RT5663_PWR_MB2_SHIFT
, 0),
2465 SND_SOC_DAPM_INPUT("IN1P"),
2466 SND_SOC_DAPM_INPUT("IN1N"),
2468 /* REC Mixer Power */
2469 SND_SOC_DAPM_SUPPLY("RECMIX1L Power", RT5663_PWR_ANLG_2
,
2470 RT5663_PWR_RECMIX1_SHIFT
, 0, NULL
, 0),
2473 SND_SOC_DAPM_ADC("ADC L", NULL
, SND_SOC_NOPM
, 0, 0),
2474 SND_SOC_DAPM_SUPPLY("ADC L Power", RT5663_PWR_DIG_1
,
2475 RT5663_PWR_ADC_L1_SHIFT
, 0, NULL
, 0),
2476 SND_SOC_DAPM_SUPPLY("ADC Clock", RT5663_CHOP_ADC
,
2477 RT5663_CKGEN_ADCC_SHIFT
, 0, NULL
, 0),
2480 SND_SOC_DAPM_MIXER("STO1 ADC MIXL", SND_SOC_NOPM
,
2481 0, 0, rt5663_sto1_adc_l_mix
,
2482 ARRAY_SIZE(rt5663_sto1_adc_l_mix
)),
2484 /* ADC Filter Power */
2485 SND_SOC_DAPM_SUPPLY("STO1 ADC Filter", RT5663_PWR_DIG_2
,
2486 RT5663_PWR_ADC_S1F_SHIFT
, 0, NULL
, 0),
2488 /* Digital Interface */
2489 SND_SOC_DAPM_SUPPLY("I2S", RT5663_PWR_DIG_1
, RT5663_PWR_I2S1_SHIFT
, 0,
2491 SND_SOC_DAPM_PGA("IF DAC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2492 SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2493 SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2494 SND_SOC_DAPM_PGA("IF1 ADC1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2495 SND_SOC_DAPM_PGA("IF ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2497 /* Audio Interface */
2498 SND_SOC_DAPM_AIF_IN("AIFRX", "AIF Playback", 0, SND_SOC_NOPM
, 0, 0),
2499 SND_SOC_DAPM_AIF_OUT("AIFTX", "AIF Capture", 0, SND_SOC_NOPM
, 0, 0),
2501 /* DAC mixer before sound effect */
2502 SND_SOC_DAPM_MIXER("ADDA MIXL", SND_SOC_NOPM
, 0, 0, rt5663_adda_l_mix
,
2503 ARRAY_SIZE(rt5663_adda_l_mix
)),
2504 SND_SOC_DAPM_MIXER("ADDA MIXR", SND_SOC_NOPM
, 0, 0, rt5663_adda_r_mix
,
2505 ARRAY_SIZE(rt5663_adda_r_mix
)),
2506 SND_SOC_DAPM_PGA("DAC L1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2507 SND_SOC_DAPM_PGA("DAC R1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2510 SND_SOC_DAPM_SUPPLY("STO1 DAC Filter", RT5663_PWR_DIG_2
,
2511 RT5663_PWR_DAC_S1F_SHIFT
, 0, NULL
, 0),
2512 SND_SOC_DAPM_MIXER("STO1 DAC MIXL", SND_SOC_NOPM
, 0, 0,
2513 rt5663_sto1_dac_l_mix
, ARRAY_SIZE(rt5663_sto1_dac_l_mix
)),
2514 SND_SOC_DAPM_MIXER("STO1 DAC MIXR", SND_SOC_NOPM
, 0, 0,
2515 rt5663_sto1_dac_r_mix
, ARRAY_SIZE(rt5663_sto1_dac_r_mix
)),
2518 SND_SOC_DAPM_SUPPLY("STO1 DAC L Power", RT5663_PWR_DIG_1
,
2519 RT5663_PWR_DAC_L1_SHIFT
, 0, NULL
, 0),
2520 SND_SOC_DAPM_SUPPLY("STO1 DAC R Power", RT5663_PWR_DIG_1
,
2521 RT5663_PWR_DAC_R1_SHIFT
, 0, NULL
, 0),
2522 SND_SOC_DAPM_DAC("DAC L", NULL
, SND_SOC_NOPM
, 0, 0),
2523 SND_SOC_DAPM_DAC("DAC R", NULL
, SND_SOC_NOPM
, 0, 0),
2526 SND_SOC_DAPM_SUPPLY("HP Charge Pump", SND_SOC_NOPM
, 0, 0,
2527 rt5663_charge_pump_event
, SND_SOC_DAPM_PRE_PMU
|
2528 SND_SOC_DAPM_POST_PMD
),
2529 SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM
, 0, 0, rt5663_hp_event
,
2530 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
2533 SND_SOC_DAPM_OUTPUT("HPOL"),
2534 SND_SOC_DAPM_OUTPUT("HPOR"),
2537 static const struct snd_soc_dapm_widget rt5663_v2_specific_dapm_widgets
[] = {
2538 SND_SOC_DAPM_SUPPLY("LDO2", RT5663_PWR_ANLG_3
,
2539 RT5663_PWR_LDO2_SHIFT
, 0, NULL
, 0),
2540 SND_SOC_DAPM_SUPPLY("Mic Det Power", RT5663_PWR_VOL
,
2541 RT5663_V2_PWR_MIC_DET_SHIFT
, 0, NULL
, 0),
2542 SND_SOC_DAPM_SUPPLY("LDO DAC", RT5663_PWR_DIG_1
,
2543 RT5663_PWR_LDO_DACREF_SHIFT
, 0, NULL
, 0),
2546 SND_SOC_DAPM_SUPPLY("I2S ASRC", RT5663_ASRC_1
,
2547 RT5663_I2S1_ASRC_SHIFT
, 0, NULL
, 0),
2548 SND_SOC_DAPM_SUPPLY("DAC ASRC", RT5663_ASRC_1
,
2549 RT5663_DAC_STO1_ASRC_SHIFT
, 0, NULL
, 0),
2550 SND_SOC_DAPM_SUPPLY("ADC ASRC", RT5663_ASRC_1
,
2551 RT5663_ADC_STO1_ASRC_SHIFT
, 0, NULL
, 0),
2554 SND_SOC_DAPM_INPUT("IN2P"),
2555 SND_SOC_DAPM_INPUT("IN2N"),
2558 SND_SOC_DAPM_PGA("BST1 CBJ", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2559 SND_SOC_DAPM_SUPPLY("CBJ Power", RT5663_PWR_ANLG_3
,
2560 RT5663_PWR_CBJ_SHIFT
, 0, NULL
, 0),
2561 SND_SOC_DAPM_PGA("BST2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2562 SND_SOC_DAPM_SUPPLY("BST2 Power", SND_SOC_NOPM
, 0, 0,
2563 rt5663_bst2_power
, SND_SOC_DAPM_PRE_PMD
|
2564 SND_SOC_DAPM_POST_PMU
),
2567 SND_SOC_DAPM_MIXER("RECMIX1L", SND_SOC_NOPM
, 0, 0, rt5663_recmix1l
,
2568 ARRAY_SIZE(rt5663_recmix1l
)),
2569 SND_SOC_DAPM_MIXER("RECMIX1R", SND_SOC_NOPM
, 0, 0, rt5663_recmix1r
,
2570 ARRAY_SIZE(rt5663_recmix1r
)),
2571 SND_SOC_DAPM_SUPPLY("RECMIX1R Power", RT5663_PWR_ANLG_2
,
2572 RT5663_PWR_RECMIX2_SHIFT
, 0, NULL
, 0),
2575 SND_SOC_DAPM_ADC("ADC R", NULL
, SND_SOC_NOPM
, 0, 0),
2576 SND_SOC_DAPM_SUPPLY("ADC R Power", RT5663_PWR_DIG_1
,
2577 RT5663_PWR_ADC_R1_SHIFT
, 0, NULL
, 0),
2580 SND_SOC_DAPM_PGA("STO1 ADC L1", RT5663_STO1_ADC_MIXER
,
2581 RT5663_STO1_ADC_L1_SRC_SHIFT
, 0, NULL
, 0),
2582 SND_SOC_DAPM_PGA("STO1 ADC R1", RT5663_STO1_ADC_MIXER
,
2583 RT5663_STO1_ADC_R1_SRC_SHIFT
, 0, NULL
, 0),
2584 SND_SOC_DAPM_PGA("STO1 ADC L2", RT5663_STO1_ADC_MIXER
,
2585 RT5663_STO1_ADC_L2_SRC_SHIFT
, 1, NULL
, 0),
2586 SND_SOC_DAPM_PGA("STO1 ADC R2", RT5663_STO1_ADC_MIXER
,
2587 RT5663_STO1_ADC_R2_SRC_SHIFT
, 1, NULL
, 0),
2589 SND_SOC_DAPM_MUX("STO1 ADC L Mux", SND_SOC_NOPM
, 0, 0,
2590 &rt5663_sto1_adcl_mux
),
2591 SND_SOC_DAPM_MUX("STO1 ADC R Mux", SND_SOC_NOPM
, 0, 0,
2592 &rt5663_sto1_adcr_mux
),
2595 SND_SOC_DAPM_MIXER("STO1 ADC MIXR", SND_SOC_NOPM
, 0, 0,
2596 rt5663_sto1_adc_r_mix
, ARRAY_SIZE(rt5663_sto1_adc_r_mix
)),
2598 /* Analog DAC Clock */
2599 SND_SOC_DAPM_SUPPLY("DAC Clock", RT5663_CHOP_DAC_L
,
2600 RT5663_CKGEN_DAC1_SHIFT
, 0, NULL
, 0),
2603 SND_SOC_DAPM_SWITCH("HPO Playback", SND_SOC_NOPM
, 0, 0,
2604 &rt5663_hpo_switch
),
2607 static const struct snd_soc_dapm_widget rt5663_specific_dapm_widgets
[] = {
2608 /* System Clock Pre Divider Gating */
2609 SND_SOC_DAPM_SUPPLY("Pre Div Power", SND_SOC_NOPM
, 0, 0,
2610 rt5663_pre_div_power
, SND_SOC_DAPM_POST_PMU
|
2611 SND_SOC_DAPM_PRE_PMD
),
2614 SND_SOC_DAPM_SUPPLY("LDO ADC", RT5663_PWR_DIG_1
,
2615 RT5663_PWR_LDO_DACREF_SHIFT
, 0, NULL
, 0),
2618 SND_SOC_DAPM_SUPPLY("I2S ASRC", RT5663_ASRC_1
,
2619 RT5663_I2S1_ASRC_SHIFT
, 0, NULL
, 0),
2620 SND_SOC_DAPM_SUPPLY("DAC ASRC", RT5663_ASRC_1
,
2621 RT5663_DAC_STO1_ASRC_SHIFT
, 0, NULL
, 0),
2622 SND_SOC_DAPM_SUPPLY("ADC ASRC", RT5663_ASRC_1
,
2623 RT5663_ADC_STO1_ASRC_SHIFT
, 0, NULL
, 0),
2626 SND_SOC_DAPM_PGA("BST1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2629 SND_SOC_DAPM_PGA("STO1 ADC L1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2630 SND_SOC_DAPM_PGA("STO1 ADC L2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
2632 /* Analog DAC source */
2633 SND_SOC_DAPM_MUX("DAC L Mux", SND_SOC_NOPM
, 0, 0, &rt5663_alg_dacl_mux
),
2634 SND_SOC_DAPM_MUX("DAC R Mux", SND_SOC_NOPM
, 0, 0, &rt5663_alg_dacr_mux
),
2637 static const struct snd_soc_dapm_route rt5663_dapm_routes
[] = {
2639 { "I2S", NULL
, "PLL", rt5663_is_sys_clk_from_pll
},
2642 { "STO1 ADC Filter", NULL
, "ADC ASRC", rt5663_is_using_asrc
},
2643 { "STO1 DAC Filter", NULL
, "DAC ASRC", rt5663_is_using_asrc
},
2644 { "I2S", NULL
, "I2S ASRC", rt5663_i2s_use_asrc
},
2646 { "ADC L", NULL
, "ADC L Power" },
2647 { "ADC L", NULL
, "ADC Clock" },
2649 { "STO1 ADC L2", NULL
, "STO1 DAC MIXL" },
2651 { "STO1 ADC MIXL", "ADC1 Switch", "STO1 ADC L1" },
2652 { "STO1 ADC MIXL", "ADC2 Switch", "STO1 ADC L2" },
2653 { "STO1 ADC MIXL", NULL
, "STO1 ADC Filter" },
2655 { "IF1 ADC1", NULL
, "STO1 ADC MIXL" },
2656 { "IF ADC", NULL
, "IF1 ADC1" },
2657 { "AIFTX", NULL
, "IF ADC" },
2658 { "AIFTX", NULL
, "I2S" },
2660 { "AIFRX", NULL
, "I2S" },
2661 { "IF DAC", NULL
, "AIFRX" },
2662 { "IF1 DAC1 L", NULL
, "IF DAC" },
2663 { "IF1 DAC1 R", NULL
, "IF DAC" },
2665 { "ADDA MIXL", "ADC L Switch", "STO1 ADC MIXL" },
2666 { "ADDA MIXL", "DAC L Switch", "IF1 DAC1 L" },
2667 { "ADDA MIXL", NULL
, "STO1 DAC Filter" },
2668 { "ADDA MIXL", NULL
, "STO1 DAC L Power" },
2669 { "ADDA MIXR", "DAC R Switch", "IF1 DAC1 R" },
2670 { "ADDA MIXR", NULL
, "STO1 DAC Filter" },
2671 { "ADDA MIXR", NULL
, "STO1 DAC R Power" },
2673 { "DAC L1", NULL
, "ADDA MIXL" },
2674 { "DAC R1", NULL
, "ADDA MIXR" },
2676 { "STO1 DAC MIXL", "DAC L Switch", "DAC L1" },
2677 { "STO1 DAC MIXL", NULL
, "STO1 DAC L Power" },
2678 { "STO1 DAC MIXL", NULL
, "STO1 DAC Filter" },
2679 { "STO1 DAC MIXR", "DAC R Switch", "DAC R1" },
2680 { "STO1 DAC MIXR", NULL
, "STO1 DAC R Power" },
2681 { "STO1 DAC MIXR", NULL
, "STO1 DAC Filter" },
2683 { "HP Amp", NULL
, "HP Charge Pump" },
2684 { "HP Amp", NULL
, "DAC L" },
2685 { "HP Amp", NULL
, "DAC R" },
2688 static const struct snd_soc_dapm_route rt5663_v2_specific_dapm_routes
[] = {
2689 { "MICBIAS1", NULL
, "LDO2" },
2690 { "MICBIAS2", NULL
, "LDO2" },
2692 { "BST1 CBJ", NULL
, "IN1P" },
2693 { "BST1 CBJ", NULL
, "IN1N" },
2694 { "BST1 CBJ", NULL
, "CBJ Power" },
2696 { "BST2", NULL
, "IN2P" },
2697 { "BST2", NULL
, "IN2N" },
2698 { "BST2", NULL
, "BST2 Power" },
2700 { "RECMIX1L", "BST2 Switch", "BST2" },
2701 { "RECMIX1L", "BST1 CBJ Switch", "BST1 CBJ" },
2702 { "RECMIX1L", NULL
, "RECMIX1L Power" },
2703 { "RECMIX1R", "BST2 Switch", "BST2" },
2704 { "RECMIX1R", NULL
, "RECMIX1R Power" },
2706 { "ADC L", NULL
, "RECMIX1L" },
2707 { "ADC R", NULL
, "RECMIX1R" },
2708 { "ADC R", NULL
, "ADC R Power" },
2709 { "ADC R", NULL
, "ADC Clock" },
2711 { "STO1 ADC L Mux", "ADC L", "ADC L" },
2712 { "STO1 ADC L Mux", "ADC R", "ADC R" },
2713 { "STO1 ADC L1", NULL
, "STO1 ADC L Mux" },
2715 { "STO1 ADC R Mux", "ADC L", "ADC L" },
2716 { "STO1 ADC R Mux", "ADC R", "ADC R" },
2717 { "STO1 ADC R1", NULL
, "STO1 ADC R Mux" },
2718 { "STO1 ADC R2", NULL
, "STO1 DAC MIXR" },
2720 { "STO1 ADC MIXR", "ADC1 Switch", "STO1 ADC R1" },
2721 { "STO1 ADC MIXR", "ADC2 Switch", "STO1 ADC R2" },
2722 { "STO1 ADC MIXR", NULL
, "STO1 ADC Filter" },
2724 { "IF1 ADC1", NULL
, "STO1 ADC MIXR" },
2726 { "ADDA MIXR", "ADC R Switch", "STO1 ADC MIXR" },
2728 { "DAC L", NULL
, "STO1 DAC MIXL" },
2729 { "DAC L", NULL
, "LDO DAC" },
2730 { "DAC L", NULL
, "DAC Clock" },
2731 { "DAC R", NULL
, "STO1 DAC MIXR" },
2732 { "DAC R", NULL
, "LDO DAC" },
2733 { "DAC R", NULL
, "DAC Clock" },
2735 { "HPO Playback", "Switch", "HP Amp" },
2736 { "HPOL", NULL
, "HPO Playback" },
2737 { "HPOR", NULL
, "HPO Playback" },
2740 static const struct snd_soc_dapm_route rt5663_specific_dapm_routes
[] = {
2741 { "I2S", NULL
, "Pre Div Power" },
2743 { "BST1", NULL
, "IN1P" },
2744 { "BST1", NULL
, "IN1N" },
2745 { "BST1", NULL
, "RECMIX1L Power" },
2747 { "ADC L", NULL
, "BST1" },
2749 { "STO1 ADC L1", NULL
, "ADC L" },
2751 { "DAC L Mux", "DAC L", "DAC L1" },
2752 { "DAC L Mux", "STO DAC MIXL", "STO1 DAC MIXL" },
2753 { "DAC R Mux", "DAC R", "DAC R1"},
2754 { "DAC R Mux", "STO DAC MIXR", "STO1 DAC MIXR" },
2756 { "DAC L", NULL
, "DAC L Mux" },
2757 { "DAC R", NULL
, "DAC R Mux" },
2759 { "HPOL", NULL
, "HP Amp" },
2760 { "HPOR", NULL
, "HP Amp" },
2763 static int rt5663_hw_params(struct snd_pcm_substream
*substream
,
2764 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
2766 struct snd_soc_component
*component
= dai
->component
;
2767 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
2768 unsigned int val_len
= 0;
2771 rt5663
->lrck
= params_rate(params
);
2773 dev_dbg(dai
->dev
, "bclk is %dHz and sysclk is %dHz\n",
2774 rt5663
->lrck
, rt5663
->sysclk
);
2776 pre_div
= rl6231_get_clk_info(rt5663
->sysclk
, rt5663
->lrck
);
2778 dev_err(component
->dev
, "Unsupported clock setting %d for DAI %d\n",
2779 rt5663
->lrck
, dai
->id
);
2783 dev_dbg(dai
->dev
, "pre_div is %d for iis %d\n", pre_div
, dai
->id
);
2785 switch (params_width(params
)) {
2787 val_len
= RT5663_I2S_DL_8
;
2790 val_len
= RT5663_I2S_DL_16
;
2793 val_len
= RT5663_I2S_DL_20
;
2796 val_len
= RT5663_I2S_DL_24
;
2802 snd_soc_component_update_bits(component
, RT5663_I2S1_SDP
,
2803 RT5663_I2S_DL_MASK
, val_len
);
2805 snd_soc_component_update_bits(component
, RT5663_ADDA_CLK_1
,
2806 RT5663_I2S_PD1_MASK
, pre_div
<< RT5663_I2S_PD1_SHIFT
);
2811 static int rt5663_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
2813 struct snd_soc_component
*component
= dai
->component
;
2814 unsigned int reg_val
= 0;
2816 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
2817 case SND_SOC_DAIFMT_CBM_CFM
:
2819 case SND_SOC_DAIFMT_CBS_CFS
:
2820 reg_val
|= RT5663_I2S_MS_S
;
2826 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
2827 case SND_SOC_DAIFMT_NB_NF
:
2829 case SND_SOC_DAIFMT_IB_NF
:
2830 reg_val
|= RT5663_I2S_BP_INV
;
2836 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
2837 case SND_SOC_DAIFMT_I2S
:
2839 case SND_SOC_DAIFMT_LEFT_J
:
2840 reg_val
|= RT5663_I2S_DF_LEFT
;
2842 case SND_SOC_DAIFMT_DSP_A
:
2843 reg_val
|= RT5663_I2S_DF_PCM_A
;
2845 case SND_SOC_DAIFMT_DSP_B
:
2846 reg_val
|= RT5663_I2S_DF_PCM_B
;
2852 snd_soc_component_update_bits(component
, RT5663_I2S1_SDP
, RT5663_I2S_MS_MASK
|
2853 RT5663_I2S_BP_MASK
| RT5663_I2S_DF_MASK
, reg_val
);
2858 static int rt5663_set_dai_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
2859 unsigned int freq
, int dir
)
2861 struct snd_soc_component
*component
= dai
->component
;
2862 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
2863 unsigned int reg_val
= 0;
2865 if (freq
== rt5663
->sysclk
&& clk_id
== rt5663
->sysclk_src
)
2869 case RT5663_SCLK_S_MCLK
:
2870 reg_val
|= RT5663_SCLK_SRC_MCLK
;
2872 case RT5663_SCLK_S_PLL1
:
2873 reg_val
|= RT5663_SCLK_SRC_PLL1
;
2875 case RT5663_SCLK_S_RCCLK
:
2876 reg_val
|= RT5663_SCLK_SRC_RCCLK
;
2879 dev_err(component
->dev
, "Invalid clock id (%d)\n", clk_id
);
2882 snd_soc_component_update_bits(component
, RT5663_GLB_CLK
, RT5663_SCLK_SRC_MASK
,
2884 rt5663
->sysclk
= freq
;
2885 rt5663
->sysclk_src
= clk_id
;
2887 dev_dbg(component
->dev
, "Sysclk is %dHz and clock id is %d\n",
2893 static int rt5663_set_dai_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
2894 unsigned int freq_in
, unsigned int freq_out
)
2896 struct snd_soc_component
*component
= dai
->component
;
2897 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
2898 struct rl6231_pll_code pll_code
;
2900 int mask
, shift
, val
;
2902 if (source
== rt5663
->pll_src
&& freq_in
== rt5663
->pll_in
&&
2903 freq_out
== rt5663
->pll_out
)
2906 if (!freq_in
|| !freq_out
) {
2907 dev_dbg(component
->dev
, "PLL disabled\n");
2910 rt5663
->pll_out
= 0;
2911 snd_soc_component_update_bits(component
, RT5663_GLB_CLK
,
2912 RT5663_SCLK_SRC_MASK
, RT5663_SCLK_SRC_MCLK
);
2916 switch (rt5663
->codec_ver
) {
2918 mask
= RT5663_V2_PLL1_SRC_MASK
;
2919 shift
= RT5663_V2_PLL1_SRC_SHIFT
;
2922 mask
= RT5663_PLL1_SRC_MASK
;
2923 shift
= RT5663_PLL1_SRC_SHIFT
;
2926 dev_err(component
->dev
, "Unknown CODEC Version\n");
2931 case RT5663_PLL1_S_MCLK
:
2934 case RT5663_PLL1_S_BCLK1
:
2938 dev_err(component
->dev
, "Unknown PLL source %d\n", source
);
2941 snd_soc_component_update_bits(component
, RT5663_GLB_CLK
, mask
, (val
<< shift
));
2943 ret
= rl6231_pll_calc(freq_in
, freq_out
, &pll_code
);
2945 dev_err(component
->dev
, "Unsupported input clock %d\n", freq_in
);
2949 dev_dbg(component
->dev
, "bypass=%d m=%d n=%d k=%d\n", pll_code
.m_bp
,
2950 (pll_code
.m_bp
? 0 : pll_code
.m_code
), pll_code
.n_code
,
2953 snd_soc_component_write(component
, RT5663_PLL_1
,
2954 pll_code
.n_code
<< RT5663_PLL_N_SHIFT
| pll_code
.k_code
);
2955 snd_soc_component_write(component
, RT5663_PLL_2
,
2956 ((pll_code
.m_bp
? 0 : pll_code
.m_code
) << RT5663_PLL_M_SHIFT
) |
2957 (pll_code
.m_bp
<< RT5663_PLL_M_BP_SHIFT
));
2959 rt5663
->pll_in
= freq_in
;
2960 rt5663
->pll_out
= freq_out
;
2961 rt5663
->pll_src
= source
;
2966 static int rt5663_set_tdm_slot(struct snd_soc_dai
*dai
, unsigned int tx_mask
,
2967 unsigned int rx_mask
, int slots
, int slot_width
)
2969 struct snd_soc_component
*component
= dai
->component
;
2970 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
2971 unsigned int val
= 0, reg
;
2973 if (rx_mask
|| tx_mask
)
2974 val
|= RT5663_TDM_MODE_TDM
;
2978 val
|= RT5663_TDM_IN_CH_4
;
2979 val
|= RT5663_TDM_OUT_CH_4
;
2982 val
|= RT5663_TDM_IN_CH_6
;
2983 val
|= RT5663_TDM_OUT_CH_6
;
2986 val
|= RT5663_TDM_IN_CH_8
;
2987 val
|= RT5663_TDM_OUT_CH_8
;
2995 switch (slot_width
) {
2997 val
|= RT5663_TDM_IN_LEN_20
;
2998 val
|= RT5663_TDM_OUT_LEN_20
;
3001 val
|= RT5663_TDM_IN_LEN_24
;
3002 val
|= RT5663_TDM_OUT_LEN_24
;
3005 val
|= RT5663_TDM_IN_LEN_32
;
3006 val
|= RT5663_TDM_OUT_LEN_32
;
3014 switch (rt5663
->codec_ver
) {
3022 dev_err(component
->dev
, "Unknown CODEC Version\n");
3026 snd_soc_component_update_bits(component
, reg
, RT5663_TDM_MODE_MASK
|
3027 RT5663_TDM_IN_CH_MASK
| RT5663_TDM_OUT_CH_MASK
|
3028 RT5663_TDM_IN_LEN_MASK
| RT5663_TDM_OUT_LEN_MASK
, val
);
3033 static int rt5663_set_bclk_ratio(struct snd_soc_dai
*dai
, unsigned int ratio
)
3035 struct snd_soc_component
*component
= dai
->component
;
3036 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
3039 dev_dbg(component
->dev
, "%s ratio = %d\n", __func__
, ratio
);
3041 if (rt5663
->codec_ver
== CODEC_VER_1
)
3048 snd_soc_component_update_bits(component
, reg
,
3049 RT5663_TDM_LENGTN_MASK
,
3050 RT5663_TDM_LENGTN_16
);
3053 snd_soc_component_update_bits(component
, reg
,
3054 RT5663_TDM_LENGTN_MASK
,
3055 RT5663_TDM_LENGTN_20
);
3058 snd_soc_component_update_bits(component
, reg
,
3059 RT5663_TDM_LENGTN_MASK
,
3060 RT5663_TDM_LENGTN_24
);
3063 snd_soc_component_update_bits(component
, reg
,
3064 RT5663_TDM_LENGTN_MASK
,
3065 RT5663_TDM_LENGTN_32
);
3068 dev_err(component
->dev
, "Invalid ratio!\n");
3075 static int rt5663_set_bias_level(struct snd_soc_component
*component
,
3076 enum snd_soc_bias_level level
)
3078 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
3081 case SND_SOC_BIAS_ON
:
3082 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_1
,
3083 RT5663_PWR_FV1_MASK
| RT5663_PWR_FV2_MASK
,
3084 RT5663_PWR_FV1
| RT5663_PWR_FV2
);
3087 case SND_SOC_BIAS_PREPARE
:
3088 if (rt5663
->codec_ver
== CODEC_VER_1
) {
3089 snd_soc_component_update_bits(component
, RT5663_DIG_MISC
,
3090 RT5663_DIG_GATE_CTRL_MASK
,
3091 RT5663_DIG_GATE_CTRL_EN
);
3092 snd_soc_component_update_bits(component
, RT5663_SIG_CLK_DET
,
3093 RT5663_EN_ANA_CLK_DET_MASK
|
3094 RT5663_PWR_CLK_DET_MASK
,
3095 RT5663_EN_ANA_CLK_DET_AUTO
|
3096 RT5663_PWR_CLK_DET_EN
);
3100 case SND_SOC_BIAS_STANDBY
:
3101 if (rt5663
->codec_ver
== CODEC_VER_1
)
3102 snd_soc_component_update_bits(component
, RT5663_DIG_MISC
,
3103 RT5663_DIG_GATE_CTRL_MASK
,
3104 RT5663_DIG_GATE_CTRL_DIS
);
3105 snd_soc_component_update_bits(component
, RT5663_PWR_ANLG_1
,
3106 RT5663_PWR_VREF1_MASK
| RT5663_PWR_VREF2_MASK
|
3107 RT5663_PWR_FV1_MASK
| RT5663_PWR_FV2_MASK
|
3108 RT5663_PWR_MB_MASK
, RT5663_PWR_VREF1
|
3109 RT5663_PWR_VREF2
| RT5663_PWR_MB
);
3110 usleep_range(10000, 10005);
3111 if (rt5663
->codec_ver
== CODEC_VER_1
) {
3112 snd_soc_component_update_bits(component
, RT5663_SIG_CLK_DET
,
3113 RT5663_EN_ANA_CLK_DET_MASK
|
3114 RT5663_PWR_CLK_DET_MASK
,
3115 RT5663_EN_ANA_CLK_DET_DIS
|
3116 RT5663_PWR_CLK_DET_DIS
);
3120 case SND_SOC_BIAS_OFF
:
3121 if (rt5663
->jack_type
!= SND_JACK_HEADSET
)
3122 snd_soc_component_update_bits(component
,
3124 RT5663_PWR_VREF1_MASK
| RT5663_PWR_VREF2_MASK
|
3125 RT5663_PWR_FV1
| RT5663_PWR_FV2
|
3126 RT5663_PWR_MB_MASK
, 0);
3128 snd_soc_component_update_bits(component
,
3130 RT5663_PWR_FV1_MASK
| RT5663_PWR_FV2_MASK
,
3131 RT5663_PWR_FV1
| RT5663_PWR_FV2
);
3141 static int rt5663_probe(struct snd_soc_component
*component
)
3143 struct snd_soc_dapm_context
*dapm
= snd_soc_component_get_dapm(component
);
3144 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
3146 rt5663
->component
= component
;
3148 switch (rt5663
->codec_ver
) {
3150 snd_soc_dapm_new_controls(dapm
,
3151 rt5663_v2_specific_dapm_widgets
,
3152 ARRAY_SIZE(rt5663_v2_specific_dapm_widgets
));
3153 snd_soc_dapm_add_routes(dapm
,
3154 rt5663_v2_specific_dapm_routes
,
3155 ARRAY_SIZE(rt5663_v2_specific_dapm_routes
));
3156 snd_soc_add_component_controls(component
, rt5663_v2_specific_controls
,
3157 ARRAY_SIZE(rt5663_v2_specific_controls
));
3160 snd_soc_dapm_new_controls(dapm
,
3161 rt5663_specific_dapm_widgets
,
3162 ARRAY_SIZE(rt5663_specific_dapm_widgets
));
3163 snd_soc_dapm_add_routes(dapm
,
3164 rt5663_specific_dapm_routes
,
3165 ARRAY_SIZE(rt5663_specific_dapm_routes
));
3166 snd_soc_add_component_controls(component
, rt5663_specific_controls
,
3167 ARRAY_SIZE(rt5663_specific_controls
));
3169 if (!rt5663
->imp_table
)
3170 snd_soc_add_component_controls(component
, rt5663_hpvol_controls
,
3171 ARRAY_SIZE(rt5663_hpvol_controls
));
3178 static void rt5663_remove(struct snd_soc_component
*component
)
3180 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
3182 regmap_write(rt5663
->regmap
, RT5663_RESET
, 0);
3186 static int rt5663_suspend(struct snd_soc_component
*component
)
3188 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
3191 disable_irq(rt5663
->irq
);
3193 cancel_delayed_work_sync(&rt5663
->jack_detect_work
);
3194 cancel_delayed_work_sync(&rt5663
->jd_unplug_work
);
3196 regcache_cache_only(rt5663
->regmap
, true);
3197 regcache_mark_dirty(rt5663
->regmap
);
3202 static int rt5663_resume(struct snd_soc_component
*component
)
3204 struct rt5663_priv
*rt5663
= snd_soc_component_get_drvdata(component
);
3206 regcache_cache_only(rt5663
->regmap
, false);
3207 regcache_sync(rt5663
->regmap
);
3209 rt5663_irq(0, rt5663
);
3212 enable_irq(rt5663
->irq
);
3217 #define rt5663_suspend NULL
3218 #define rt5663_resume NULL
3221 #define RT5663_STEREO_RATES SNDRV_PCM_RATE_8000_192000
3222 #define RT5663_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
3223 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
3225 static const struct snd_soc_dai_ops rt5663_aif_dai_ops
= {
3226 .hw_params
= rt5663_hw_params
,
3227 .set_fmt
= rt5663_set_dai_fmt
,
3228 .set_sysclk
= rt5663_set_dai_sysclk
,
3229 .set_pll
= rt5663_set_dai_pll
,
3230 .set_tdm_slot
= rt5663_set_tdm_slot
,
3231 .set_bclk_ratio
= rt5663_set_bclk_ratio
,
3234 static struct snd_soc_dai_driver rt5663_dai
[] = {
3236 .name
= "rt5663-aif",
3239 .stream_name
= "AIF Playback",
3242 .rates
= RT5663_STEREO_RATES
,
3243 .formats
= RT5663_FORMATS
,
3246 .stream_name
= "AIF Capture",
3249 .rates
= RT5663_STEREO_RATES
,
3250 .formats
= RT5663_FORMATS
,
3252 .ops
= &rt5663_aif_dai_ops
,
3256 static const struct snd_soc_component_driver soc_component_dev_rt5663
= {
3257 .probe
= rt5663_probe
,
3258 .remove
= rt5663_remove
,
3259 .suspend
= rt5663_suspend
,
3260 .resume
= rt5663_resume
,
3261 .set_bias_level
= rt5663_set_bias_level
,
3262 .controls
= rt5663_snd_controls
,
3263 .num_controls
= ARRAY_SIZE(rt5663_snd_controls
),
3264 .dapm_widgets
= rt5663_dapm_widgets
,
3265 .num_dapm_widgets
= ARRAY_SIZE(rt5663_dapm_widgets
),
3266 .dapm_routes
= rt5663_dapm_routes
,
3267 .num_dapm_routes
= ARRAY_SIZE(rt5663_dapm_routes
),
3268 .set_jack
= rt5663_set_jack_detect
,
3269 .use_pmdown_time
= 1,
3273 static const struct regmap_config rt5663_v2_regmap
= {
3276 .use_single_read
= true,
3277 .use_single_write
= true,
3278 .max_register
= 0x07fa,
3279 .volatile_reg
= rt5663_v2_volatile_register
,
3280 .readable_reg
= rt5663_v2_readable_register
,
3281 .cache_type
= REGCACHE_MAPLE
,
3282 .reg_defaults
= rt5663_v2_reg
,
3283 .num_reg_defaults
= ARRAY_SIZE(rt5663_v2_reg
),
3286 static const struct regmap_config rt5663_regmap
= {
3289 .use_single_read
= true,
3290 .use_single_write
= true,
3291 .max_register
= 0x03f3,
3292 .volatile_reg
= rt5663_volatile_register
,
3293 .readable_reg
= rt5663_readable_register
,
3294 .cache_type
= REGCACHE_MAPLE
,
3295 .reg_defaults
= rt5663_reg
,
3296 .num_reg_defaults
= ARRAY_SIZE(rt5663_reg
),
3299 static const struct regmap_config temp_regmap
= {
3303 .use_single_read
= true,
3304 .use_single_write
= true,
3305 .max_register
= 0x03f3,
3306 .cache_type
= REGCACHE_NONE
,
3309 static const struct i2c_device_id rt5663_i2c_id
[] = {
3313 MODULE_DEVICE_TABLE(i2c
, rt5663_i2c_id
);
3315 #if defined(CONFIG_OF)
3316 static const struct of_device_id rt5663_of_match
[] = {
3317 { .compatible
= "realtek,rt5663", },
3320 MODULE_DEVICE_TABLE(of
, rt5663_of_match
);
3324 static const struct acpi_device_id rt5663_acpi_match
[] = {
3328 MODULE_DEVICE_TABLE(acpi
, rt5663_acpi_match
);
3331 static void rt5663_v2_calibrate(struct rt5663_priv
*rt5663
)
3333 regmap_write(rt5663
->regmap
, RT5663_BIAS_CUR_8
, 0xa402);
3334 regmap_write(rt5663
->regmap
, RT5663_PWR_DIG_1
, 0x0100);
3335 regmap_write(rt5663
->regmap
, RT5663_RECMIX
, 0x4040);
3336 regmap_write(rt5663
->regmap
, RT5663_DIG_MISC
, 0x0001);
3337 regmap_write(rt5663
->regmap
, RT5663_RC_CLK
, 0x0380);
3338 regmap_write(rt5663
->regmap
, RT5663_GLB_CLK
, 0x8000);
3339 regmap_write(rt5663
->regmap
, RT5663_ADDA_CLK_1
, 0x1000);
3340 regmap_write(rt5663
->regmap
, RT5663_CHOP_DAC_L
, 0x3030);
3341 regmap_write(rt5663
->regmap
, RT5663_CALIB_ADC
, 0x3c05);
3342 regmap_write(rt5663
->regmap
, RT5663_PWR_ANLG_1
, 0xa23e);
3344 regmap_write(rt5663
->regmap
, RT5663_PWR_ANLG_1
, 0xf23e);
3345 regmap_write(rt5663
->regmap
, RT5663_HP_CALIB_2
, 0x0321);
3346 regmap_write(rt5663
->regmap
, RT5663_HP_CALIB_1
, 0xfc00);
3350 static void rt5663_calibrate(struct rt5663_priv
*rt5663
)
3354 regmap_write(rt5663
->regmap
, RT5663_RESET
, 0x0000);
3356 regmap_write(rt5663
->regmap
, RT5663_ANA_BIAS_CUR_4
, 0x00a1);
3357 regmap_write(rt5663
->regmap
, RT5663_RC_CLK
, 0x0380);
3358 regmap_write(rt5663
->regmap
, RT5663_GLB_CLK
, 0x8000);
3359 regmap_write(rt5663
->regmap
, RT5663_ADDA_CLK_1
, 0x1000);
3360 regmap_write(rt5663
->regmap
, RT5663_VREF_RECMIX
, 0x0032);
3361 regmap_write(rt5663
->regmap
, RT5663_HP_IMP_SEN_19
, 0x000c);
3362 regmap_write(rt5663
->regmap
, RT5663_DUMMY_1
, 0x0324);
3363 regmap_write(rt5663
->regmap
, RT5663_DIG_MISC
, 0x8001);
3364 regmap_write(rt5663
->regmap
, RT5663_VREFADJ_OP
, 0x0f28);
3365 regmap_write(rt5663
->regmap
, RT5663_PWR_ANLG_1
, 0xa23b);
3367 regmap_write(rt5663
->regmap
, RT5663_PWR_ANLG_1
, 0xf23b);
3368 regmap_write(rt5663
->regmap
, RT5663_PWR_ANLG_2
, 0x8000);
3369 regmap_write(rt5663
->regmap
, RT5663_PWR_ANLG_3
, 0x0008);
3370 regmap_write(rt5663
->regmap
, RT5663_PRE_DIV_GATING_1
, 0xffff);
3371 regmap_write(rt5663
->regmap
, RT5663_PRE_DIV_GATING_2
, 0xffff);
3372 regmap_write(rt5663
->regmap
, RT5663_CBJ_1
, 0x8c10);
3373 regmap_write(rt5663
->regmap
, RT5663_IL_CMD_2
, 0x00c1);
3374 regmap_write(rt5663
->regmap
, RT5663_EM_JACK_TYPE_1
, 0xb880);
3375 regmap_write(rt5663
->regmap
, RT5663_EM_JACK_TYPE_2
, 0x4110);
3376 regmap_write(rt5663
->regmap
, RT5663_EM_JACK_TYPE_2
, 0x4118);
3380 regmap_read(rt5663
->regmap
, RT5663_INT_ST_2
, &value
);
3381 if (!(value
& 0x80))
3382 usleep_range(10000, 10005);
3390 regmap_write(rt5663
->regmap
, RT5663_HP_IMP_SEN_19
, 0x0000);
3391 regmap_write(rt5663
->regmap
, RT5663_DEPOP_2
, 0x3003);
3392 regmap_write(rt5663
->regmap
, RT5663_DEPOP_1
, 0x0038);
3393 regmap_write(rt5663
->regmap
, RT5663_DEPOP_1
, 0x003b);
3394 regmap_write(rt5663
->regmap
, RT5663_PWR_DIG_2
, 0x8400);
3395 regmap_write(rt5663
->regmap
, RT5663_PWR_DIG_1
, 0x8df8);
3396 regmap_write(rt5663
->regmap
, RT5663_PWR_ANLG_2
, 0x8003);
3397 regmap_write(rt5663
->regmap
, RT5663_PWR_ANLG_3
, 0x018c);
3398 regmap_write(rt5663
->regmap
, RT5663_HP_CHARGE_PUMP_1
, 0x1e32);
3399 regmap_write(rt5663
->regmap
, RT5663_DUMMY_2
, 0x8089);
3400 regmap_write(rt5663
->regmap
, RT5663_DACREF_LDO
, 0x3b0b);
3402 regmap_write(rt5663
->regmap
, RT5663_STO_DAC_MIXER
, 0x0000);
3403 regmap_write(rt5663
->regmap
, RT5663_BYPASS_STO_DAC
, 0x000c);
3404 regmap_write(rt5663
->regmap
, RT5663_HP_BIAS
, 0xafaa);
3405 regmap_write(rt5663
->regmap
, RT5663_CHARGE_PUMP_1
, 0x2224);
3406 regmap_write(rt5663
->regmap
, RT5663_HP_OUT_EN
, 0x8088);
3407 regmap_write(rt5663
->regmap
, RT5663_STO_DRE_9
, 0x0017);
3408 regmap_write(rt5663
->regmap
, RT5663_STO_DRE_10
, 0x0017);
3409 regmap_write(rt5663
->regmap
, RT5663_STO1_ADC_MIXER
, 0x4040);
3410 regmap_write(rt5663
->regmap
, RT5663_CHOP_ADC
, 0x3000);
3411 regmap_write(rt5663
->regmap
, RT5663_RECMIX
, 0x0005);
3412 regmap_write(rt5663
->regmap
, RT5663_ADDA_RST
, 0xc000);
3413 regmap_write(rt5663
->regmap
, RT5663_STO1_HPF_ADJ1
, 0x3320);
3414 regmap_write(rt5663
->regmap
, RT5663_HP_CALIB_2
, 0x00c9);
3415 regmap_write(rt5663
->regmap
, RT5663_DUMMY_1
, 0x004c);
3416 regmap_write(rt5663
->regmap
, RT5663_ANA_BIAS_CUR_1
, 0x1111);
3417 regmap_write(rt5663
->regmap
, RT5663_BIAS_CUR_8
, 0x4402);
3418 regmap_write(rt5663
->regmap
, RT5663_CHARGE_PUMP_2
, 0x3311);
3419 regmap_write(rt5663
->regmap
, RT5663_HP_CALIB_1
, 0x0069);
3420 regmap_write(rt5663
->regmap
, RT5663_HP_CALIB_3
, 0x06ce);
3421 regmap_write(rt5663
->regmap
, RT5663_HP_CALIB_1_1
, 0x6800);
3422 regmap_write(rt5663
->regmap
, RT5663_CHARGE_PUMP_2
, 0x1100);
3423 regmap_write(rt5663
->regmap
, RT5663_HP_CALIB_7
, 0x0057);
3424 regmap_write(rt5663
->regmap
, RT5663_HP_CALIB_1_1
, 0xe800);
3428 regmap_read(rt5663
->regmap
, RT5663_HP_CALIB_1_1
, &value
);
3430 usleep_range(10000, 10005);
3439 regmap_write(rt5663
->regmap
, RT5663_HP_CALIB_1_1
, 0x6200);
3440 regmap_write(rt5663
->regmap
, RT5663_HP_CALIB_7
, 0x0059);
3441 regmap_write(rt5663
->regmap
, RT5663_HP_CALIB_1_1
, 0xe200);
3445 regmap_read(rt5663
->regmap
, RT5663_HP_CALIB_1_1
, &value
);
3447 usleep_range(10000, 10005);
3456 regmap_write(rt5663
->regmap
, RT5663_EM_JACK_TYPE_1
, 0xb8e0);
3457 usleep_range(10000, 10005);
3458 regmap_write(rt5663
->regmap
, RT5663_PWR_ANLG_1
, 0x003b);
3459 usleep_range(10000, 10005);
3460 regmap_write(rt5663
->regmap
, RT5663_PWR_DIG_1
, 0x0000);
3461 usleep_range(10000, 10005);
3462 regmap_write(rt5663
->regmap
, RT5663_DEPOP_1
, 0x000b);
3463 usleep_range(10000, 10005);
3464 regmap_write(rt5663
->regmap
, RT5663_DEPOP_1
, 0x0008);
3465 usleep_range(10000, 10005);
3466 regmap_write(rt5663
->regmap
, RT5663_PWR_ANLG_2
, 0x0000);
3467 usleep_range(10000, 10005);
3470 static int rt5663_parse_dp(struct rt5663_priv
*rt5663
, struct device
*dev
)
3475 device_property_read_u32(dev
, "realtek,dc_offset_l_manual",
3476 &rt5663
->pdata
.dc_offset_l_manual
);
3477 device_property_read_u32(dev
, "realtek,dc_offset_r_manual",
3478 &rt5663
->pdata
.dc_offset_r_manual
);
3479 device_property_read_u32(dev
, "realtek,dc_offset_l_manual_mic",
3480 &rt5663
->pdata
.dc_offset_l_manual_mic
);
3481 device_property_read_u32(dev
, "realtek,dc_offset_r_manual_mic",
3482 &rt5663
->pdata
.dc_offset_r_manual_mic
);
3483 device_property_read_u32(dev
, "realtek,impedance_sensing_num",
3484 &rt5663
->pdata
.impedance_sensing_num
);
3486 if (rt5663
->pdata
.impedance_sensing_num
) {
3487 table_size
= sizeof(struct impedance_mapping_table
) *
3488 rt5663
->pdata
.impedance_sensing_num
;
3489 rt5663
->imp_table
= devm_kzalloc(dev
, table_size
, GFP_KERNEL
);
3490 if (!rt5663
->imp_table
)
3492 ret
= device_property_read_u32_array(dev
,
3493 "realtek,impedance_sensing_table",
3494 (u32
*)rt5663
->imp_table
, table_size
);
3502 static int rt5663_i2c_probe(struct i2c_client
*i2c
)
3504 struct rt5663_platform_data
*pdata
= dev_get_platdata(&i2c
->dev
);
3505 struct rt5663_priv
*rt5663
;
3508 struct regmap
*regmap
;
3510 rt5663
= devm_kzalloc(&i2c
->dev
, sizeof(struct rt5663_priv
),
3516 i2c_set_clientdata(i2c
, rt5663
);
3519 rt5663
->pdata
= *pdata
;
3521 ret
= rt5663_parse_dp(rt5663
, &i2c
->dev
);
3526 for (i
= 0; i
< ARRAY_SIZE(rt5663
->supplies
); i
++)
3527 rt5663
->supplies
[i
].supply
= rt5663_supply_names
[i
];
3529 ret
= devm_regulator_bulk_get(&i2c
->dev
,
3530 ARRAY_SIZE(rt5663
->supplies
),
3533 dev_err(&i2c
->dev
, "Failed to request supplies: %d\n", ret
);
3537 /* Set load for regulator. */
3538 for (i
= 0; i
< ARRAY_SIZE(rt5663
->supplies
); i
++) {
3539 ret
= regulator_set_load(rt5663
->supplies
[i
].consumer
,
3540 RT5663_SUPPLY_CURRENT_UA
);
3543 "Failed to set regulator load on %s, ret: %d\n",
3544 rt5663
->supplies
[i
].supply
, ret
);
3549 ret
= regulator_bulk_enable(ARRAY_SIZE(rt5663
->supplies
),
3553 dev_err(&i2c
->dev
, "Failed to enable supplies: %d\n", ret
);
3556 msleep(RT5663_POWER_ON_DELAY_MS
);
3558 regmap
= devm_regmap_init_i2c(i2c
, &temp_regmap
);
3559 if (IS_ERR(regmap
)) {
3560 ret
= PTR_ERR(regmap
);
3561 dev_err(&i2c
->dev
, "Failed to allocate temp register map: %d\n",
3566 ret
= regmap_read(regmap
, RT5663_VENDOR_ID_2
, &val
);
3567 if (ret
|| (val
!= RT5663_DEVICE_ID_2
&& val
!= RT5663_DEVICE_ID_1
)) {
3569 "Device with ID register %#x is not rt5663, retry one time.\n",
3572 regmap_read(regmap
, RT5663_VENDOR_ID_2
, &val
);
3576 case RT5663_DEVICE_ID_2
:
3577 rt5663
->regmap
= devm_regmap_init_i2c(i2c
, &rt5663_v2_regmap
);
3578 rt5663
->codec_ver
= CODEC_VER_1
;
3580 case RT5663_DEVICE_ID_1
:
3581 rt5663
->regmap
= devm_regmap_init_i2c(i2c
, &rt5663_regmap
);
3582 rt5663
->codec_ver
= CODEC_VER_0
;
3586 "Device with ID register %#x is not rt5663\n",
3592 if (IS_ERR(rt5663
->regmap
)) {
3593 ret
= PTR_ERR(rt5663
->regmap
);
3594 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
3599 /* reset and calibrate */
3600 regmap_write(rt5663
->regmap
, RT5663_RESET
, 0);
3601 regcache_cache_bypass(rt5663
->regmap
, true);
3602 switch (rt5663
->codec_ver
) {
3604 rt5663_v2_calibrate(rt5663
);
3607 rt5663_calibrate(rt5663
);
3610 dev_err(&i2c
->dev
, "%s:Unknown codec type\n", __func__
);
3612 regcache_cache_bypass(rt5663
->regmap
, false);
3613 regmap_write(rt5663
->regmap
, RT5663_RESET
, 0);
3614 dev_dbg(&i2c
->dev
, "calibrate done\n");
3616 switch (rt5663
->codec_ver
) {
3620 ret
= regmap_register_patch(rt5663
->regmap
, rt5663_patch_list
,
3621 ARRAY_SIZE(rt5663_patch_list
));
3624 "Failed to apply regmap patch: %d\n", ret
);
3627 dev_err(&i2c
->dev
, "%s:Unknown codec type\n", __func__
);
3631 regmap_update_bits(rt5663
->regmap
, RT5663_GPIO_1
, RT5663_GP1_PIN_MASK
,
3632 RT5663_GP1_PIN_IRQ
);
3633 /* 4btn inline command debounce */
3634 regmap_update_bits(rt5663
->regmap
, RT5663_IL_CMD_5
,
3635 RT5663_4BTN_CLK_DEB_MASK
, RT5663_4BTN_CLK_DEB_65MS
);
3637 switch (rt5663
->codec_ver
) {
3639 regmap_write(rt5663
->regmap
, RT5663_BIAS_CUR_8
, 0xa402);
3641 regmap_update_bits(rt5663
->regmap
, RT5663_AUTO_1MRC_CLK
,
3642 RT5663_IRQ_POW_SAV_MASK
| RT5663_IRQ_POW_SAV_JD1_MASK
,
3643 RT5663_IRQ_POW_SAV_EN
| RT5663_IRQ_POW_SAV_JD1_EN
);
3644 regmap_update_bits(rt5663
->regmap
, RT5663_PWR_ANLG_2
,
3645 RT5663_PWR_JD1_MASK
, RT5663_PWR_JD1
);
3646 regmap_update_bits(rt5663
->regmap
, RT5663_IRQ_1
,
3647 RT5663_EN_CB_JD_MASK
, RT5663_EN_CB_JD_EN
);
3649 regmap_update_bits(rt5663
->regmap
, RT5663_HP_LOGIC_2
,
3650 RT5663_HP_SIG_SRC1_MASK
, RT5663_HP_SIG_SRC1_REG
);
3651 regmap_update_bits(rt5663
->regmap
, RT5663_RECMIX
,
3652 RT5663_VREF_BIAS_MASK
| RT5663_CBJ_DET_MASK
|
3653 RT5663_DET_TYPE_MASK
, RT5663_VREF_BIAS_REG
|
3654 RT5663_CBJ_DET_EN
| RT5663_DET_TYPE_QFN
);
3655 /* Set GPIO4 and GPIO8 as input for combo jack */
3656 regmap_update_bits(rt5663
->regmap
, RT5663_GPIO_2
,
3657 RT5663_GP4_PIN_CONF_MASK
, RT5663_GP4_PIN_CONF_INPUT
);
3658 regmap_update_bits(rt5663
->regmap
, RT5663_GPIO_3
,
3659 RT5663_GP8_PIN_CONF_MASK
, RT5663_GP8_PIN_CONF_INPUT
);
3660 regmap_update_bits(rt5663
->regmap
, RT5663_PWR_ANLG_1
,
3661 RT5663_LDO1_DVO_MASK
| RT5663_AMP_HP_MASK
,
3662 RT5663_LDO1_DVO_0_9V
| RT5663_AMP_HP_3X
);
3665 regmap_update_bits(rt5663
->regmap
, RT5663_DIG_MISC
,
3666 RT5663_DIG_GATE_CTRL_MASK
, RT5663_DIG_GATE_CTRL_EN
);
3667 regmap_update_bits(rt5663
->regmap
, RT5663_AUTO_1MRC_CLK
,
3668 RT5663_IRQ_MANUAL_MASK
, RT5663_IRQ_MANUAL_EN
);
3669 regmap_update_bits(rt5663
->regmap
, RT5663_IRQ_1
,
3670 RT5663_EN_IRQ_JD1_MASK
, RT5663_EN_IRQ_JD1_EN
);
3671 regmap_update_bits(rt5663
->regmap
, RT5663_GPIO_1
,
3672 RT5663_GPIO1_TYPE_MASK
, RT5663_GPIO1_TYPE_EN
);
3673 regmap_write(rt5663
->regmap
, RT5663_VREF_RECMIX
, 0x0032);
3674 regmap_update_bits(rt5663
->regmap
, RT5663_GPIO_2
,
3675 RT5663_GP1_PIN_CONF_MASK
| RT5663_SEL_GPIO1_MASK
,
3676 RT5663_GP1_PIN_CONF_OUTPUT
| RT5663_SEL_GPIO1_EN
);
3677 regmap_update_bits(rt5663
->regmap
, RT5663_RECMIX
,
3678 RT5663_RECMIX1_BST1_MASK
, RT5663_RECMIX1_BST1_ON
);
3679 regmap_update_bits(rt5663
->regmap
, RT5663_TDM_2
,
3680 RT5663_DATA_SWAP_ADCDAT1_MASK
,
3681 RT5663_DATA_SWAP_ADCDAT1_LL
);
3684 dev_err(&i2c
->dev
, "%s:Unknown codec type\n", __func__
);
3687 INIT_DELAYED_WORK(&rt5663
->jack_detect_work
, rt5663_jack_detect_work
);
3688 INIT_DELAYED_WORK(&rt5663
->jd_unplug_work
, rt5663_jd_unplug_work
);
3691 ret
= request_irq(i2c
->irq
, rt5663_irq
,
3692 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
3693 | IRQF_ONESHOT
, "rt5663", rt5663
);
3695 dev_err(&i2c
->dev
, "%s Failed to request IRQ: %d\n",
3699 rt5663
->irq
= i2c
->irq
;
3702 ret
= devm_snd_soc_register_component(&i2c
->dev
,
3703 &soc_component_dev_rt5663
,
3704 rt5663_dai
, ARRAY_SIZE(rt5663_dai
));
3713 * Error after enabling regulators should goto err_enable
3714 * to disable regulators.
3718 free_irq(i2c
->irq
, rt5663
);
3720 regulator_bulk_disable(ARRAY_SIZE(rt5663
->supplies
), rt5663
->supplies
);
3724 static void rt5663_i2c_remove(struct i2c_client
*i2c
)
3726 struct rt5663_priv
*rt5663
= i2c_get_clientdata(i2c
);
3729 free_irq(i2c
->irq
, rt5663
);
3731 regulator_bulk_disable(ARRAY_SIZE(rt5663
->supplies
), rt5663
->supplies
);
3734 static void rt5663_i2c_shutdown(struct i2c_client
*client
)
3736 struct rt5663_priv
*rt5663
= i2c_get_clientdata(client
);
3738 regmap_write(rt5663
->regmap
, RT5663_RESET
, 0);
3741 static struct i2c_driver rt5663_i2c_driver
= {
3744 .acpi_match_table
= ACPI_PTR(rt5663_acpi_match
),
3745 .of_match_table
= of_match_ptr(rt5663_of_match
),
3747 .probe
= rt5663_i2c_probe
,
3748 .remove
= rt5663_i2c_remove
,
3749 .shutdown
= rt5663_i2c_shutdown
,
3750 .id_table
= rt5663_i2c_id
,
3752 module_i2c_driver(rt5663_i2c_driver
);
3754 MODULE_DESCRIPTION("ASoC RT5663 driver");
3755 MODULE_AUTHOR("Jack Yu <jack.yu@realtek.com>");
3756 MODULE_LICENSE("GPL v2");