19 #include <linux/i2c.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
31 #define DA7210_PAGE_CONTROL 0x00
32 #define DA7210_CONTROL 0x01
33 #define DA7210_STATUS 0x02
34 #define DA7210_STARTUP1 0x03
35 #define DA7210_STARTUP2 0x04
36 #define DA7210_STARTUP3 0x05
37 #define DA7210_MIC_L 0x07
38 #define DA7210_MIC_R 0x08
39 #define DA7210_AUX1_L 0x09
40 #define DA7210_AUX1_R 0x0A
41 #define DA7210_AUX2 0x0B
42 #define DA7210_IN_GAIN 0x0C
43 #define DA7210_INMIX_L 0x0D
44 #define DA7210_INMIX_R 0x0E
45 #define DA7210_ADC_HPF 0x0F
46 #define DA7210_ADC 0x10
47 #define DA7210_ADC_EQ1_2 0X11
48 #define DA7210_ADC_EQ3_4 0x12
49 #define DA7210_ADC_EQ5 0x13
50 #define DA7210_DAC_HPF 0x14
51 #define DA7210_DAC_L 0x15
52 #define DA7210_DAC_R 0x16
53 #define DA7210_DAC_SEL 0x17
54 #define DA7210_SOFTMUTE 0x18
55 #define DA7210_DAC_EQ1_2 0x19
56 #define DA7210_DAC_EQ3_4 0x1A
57 #define DA7210_DAC_EQ5 0x1B
58 #define DA7210_OUTMIX_L 0x1C
59 #define DA7210_OUTMIX_R 0x1D
60 #define DA7210_OUT1_L 0x1E
61 #define DA7210_OUT1_R 0x1F
62 #define DA7210_OUT2 0x20
63 #define DA7210_HP_L_VOL 0x21
64 #define DA7210_HP_R_VOL 0x22
65 #define DA7210_HP_CFG 0x23
66 #define DA7210_ZERO_CROSS 0x24
67 #define DA7210_DAI_SRC_SEL 0x25
68 #define DA7210_DAI_CFG1 0x26
69 #define DA7210_DAI_CFG3 0x28
70 #define DA7210_PLL_DIV1 0x29
71 #define DA7210_PLL_DIV2 0x2A
72 #define DA7210_PLL_DIV3 0x2B
73 #define DA7210_PLL 0x2C
74 #define DA7210_ALC_MAX 0x83
75 #define DA7210_ALC_MIN 0x84
76 #define DA7210_ALC_NOIS 0x85
77 #define DA7210_ALC_ATT 0x86
78 #define DA7210_ALC_REL 0x87
79 #define DA7210_ALC_DEL 0x88
80 #define DA7210_A_HID_UNLOCK 0x8A
81 #define DA7210_A_TEST_UNLOCK 0x8B
82 #define DA7210_A_PLL1 0x90
83 #define DA7210_A_CP_MODE 0xA7
86 #define DA7210_SC_MST_EN (1 << 0)
89 #define DA7210_MICBIAS_EN (1 << 6)
90 #define DA7210_MIC_L_EN (1 << 7)
93 #define DA7210_MIC_R_EN (1 << 7)
96 #define DA7210_IN_L_EN (1 << 7)
99 #define DA7210_IN_R_EN (1 << 7)
102 #define DA7210_ADC_ALC_EN (1 << 0)
103 #define DA7210_ADC_L_EN (1 << 3)
104 #define DA7210_ADC_R_EN (1 << 7)
107 #define DA7210_VOICE_F0_MASK (0x7 << 4)
108 #define DA7210_VOICE_F0_25 (1 << 4)
109 #define DA7210_VOICE_EN (1 << 7)
112 #define DA7210_DAC_L_SRC_DAI_L (4 << 0)
113 #define DA7210_DAC_L_EN (1 << 3)
114 #define DA7210_DAC_R_SRC_DAI_R (5 << 4)
115 #define DA7210_DAC_R_EN (1 << 7)
118 #define DA7210_OUT_L_EN (1 << 7)
121 #define DA7210_OUT_R_EN (1 << 7)
124 #define DA7210_HP_2CAP_MODE (1 << 1)
125 #define DA7210_HP_SENSE_EN (1 << 2)
126 #define DA7210_HP_L_EN (1 << 3)
127 #define DA7210_HP_MODE (1 << 6)
128 #define DA7210_HP_R_EN (1 << 7)
131 #define DA7210_DAI_OUT_L_SRC (6 << 0)
132 #define DA7210_DAI_OUT_R_SRC (7 << 4)
135 #define DA7210_DAI_WORD_S16_LE (0 << 0)
136 #define DA7210_DAI_WORD_S20_3LE (1 << 0)
137 #define DA7210_DAI_WORD_S24_LE (2 << 0)
138 #define DA7210_DAI_WORD_S32_LE (3 << 0)
139 #define DA7210_DAI_FLEN_64BIT (1 << 2)
140 #define DA7210_DAI_MODE_SLAVE (0 << 7)
141 #define DA7210_DAI_MODE_MASTER (1 << 7)
144 #define DA7210_DAI_FORMAT_I2SMODE (0 << 0)
145 #define DA7210_DAI_FORMAT_LEFT_J (1 << 0)
146 #define DA7210_DAI_FORMAT_RIGHT_J (2 << 0)
147 #define DA7210_DAI_OE (1 << 3)
148 #define DA7210_DAI_EN (1 << 7)
151 #define DA7210_PLL_DIV_L_MASK (0xF << 0)
152 #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
153 #define DA7210_PLL_BYP (1 << 6)
156 #define DA7210_PLL_FS_MASK (0xF << 0)
157 #define DA7210_PLL_FS_8000 (0x1 << 0)
158 #define DA7210_PLL_FS_11025 (0x2 << 0)
159 #define DA7210_PLL_FS_12000 (0x3 << 0)
160 #define DA7210_PLL_FS_16000 (0x5 << 0)
161 #define DA7210_PLL_FS_22050 (0x6 << 0)
162 #define DA7210_PLL_FS_24000 (0x7 << 0)
163 #define DA7210_PLL_FS_32000 (0x9 << 0)
164 #define DA7210_PLL_FS_44100 (0xA << 0)
165 #define DA7210_PLL_FS_48000 (0xB << 0)
166 #define DA7210_PLL_FS_88200 (0xE << 0)
167 #define DA7210_PLL_FS_96000 (0xF << 0)
168 #define DA7210_MCLK_DET_EN (0x1 << 5)
169 #define DA7210_MCLK_SRM_EN (0x1 << 6)
170 #define DA7210_PLL_EN (0x1 << 7)
173 #define DA7210_RAMP_EN (1 << 6)
176 #define DA7210_REG_EN (1 << 0)
177 #define DA7210_BIAS_EN (1 << 2)
178 #define DA7210_NOISE_SUP_EN (1 << 3)
181 #define DA7210_INPGA_L_VOL (0x0F << 0)
182 #define DA7210_INPGA_R_VOL (0xF0 << 0)
185 #define DA7210_AUX1_L_ZC (1 << 0)
186 #define DA7210_AUX1_R_ZC (1 << 1)
187 #define DA7210_HP_L_ZC (1 << 6)
188 #define DA7210_HP_R_ZC (1 << 7)
191 #define DA7210_AUX1_L_VOL (0x3F << 0)
192 #define DA7210_AUX1_L_EN (1 << 7)
195 #define DA7210_AUX1_R_VOL (0x3F << 0)
196 #define DA7210_AUX1_R_EN (1 << 7)
199 #define DA7210_AUX2_EN (1 << 3)
202 #define DA7210_INPGA_MIN_VOL_NS 0x0A
203 #define DA7210_AUX1_MIN_VOL_NS 0x35
206 #define DA7210_OUT1_L_EN (1 << 7)
209 #define DA7210_OUT1_R_EN (1 << 7)
212 #define DA7210_OUT2_OUTMIX_R (1 << 5)
213 #define DA7210_OUT2_OUTMIX_L (1 << 6)
214 #define DA7210_OUT2_EN (1 << 7)
226 static const struct pll_div da7210_pll_div[] = {
228 { 12000000, 2822400, 0xE8, 0x6C, 0x2, 1},
229 { 13000000, 2822400, 0xDF, 0x28, 0xC, 1},
230 { 13500000, 2822400, 0xDB, 0x0A, 0xD, 1},
231 { 14400000, 2822400, 0xD4, 0x5A, 0x2, 1},
232 { 19200000, 2822400, 0xBB, 0x43, 0x9, 1},
233 { 19680000, 2822400, 0xB9, 0x6D, 0xA, 1},
234 { 19800000, 2822400, 0xB8, 0xFB, 0xB, 1},
236 { 12000000, 3072000, 0xF3, 0x12, 0x7, 1},
237 { 13000000, 3072000, 0xE8, 0xFD, 0x5, 1},
238 { 13500000, 3072000, 0xE4, 0x82, 0x3, 1},
239 { 14400000, 3072000, 0xDD, 0x3A, 0x0, 1},
240 { 19200000, 3072000, 0xC1, 0xEB, 0x8, 1},
241 { 19680000, 3072000, 0xBF, 0xEC, 0x0, 1},
242 { 19800000, 3072000, 0xBF, 0x70, 0x0, 1},
244 { 12000000, 2822400, 0xED, 0xBF, 0x5, 0},
245 { 13000000, 2822400, 0xE4, 0x13, 0x0, 0},
246 { 13500000, 2822400, 0xDF, 0xC6, 0x8, 0},
247 { 14400000, 2822400, 0xD8, 0xCA, 0x1, 0},
248 { 19200000, 2822400, 0xBE, 0x97, 0x9, 0},
249 { 19680000, 2822400, 0xBC, 0xAC, 0xD, 0},
250 { 19800000, 2822400, 0xBC, 0x35, 0xE, 0},
257 #define DA7210_VERSION "0.0.1"
270 static const unsigned int hp_out_tlv[] = {
277 static const unsigned int lineout_vol_tlv[] = {
284 static const unsigned int mono_vol_tlv[] = {
291 static const unsigned int aux1_vol_tlv[] = {
306 static const char *
const da7210_hpf_cutoff_txt[] = {
307 "Fs/8192*pi",
"Fs/4096*pi",
"Fs/2048*pi",
"Fs/1024*pi"
310 static const struct soc_enum da7210_dac_hpf_cutoff =
313 static const struct soc_enum da7210_adc_hpf_cutoff =
317 static const char *
const da7210_vf_cutoff_txt[] = {
318 "2.5Hz",
"25Hz",
"50Hz",
"100Hz",
"150Hz",
"200Hz",
"300Hz",
"400Hz"
321 static const struct soc_enum da7210_dac_vf_cutoff =
324 static const struct soc_enum da7210_adc_vf_cutoff =
327 static const char *da7210_hp_mode_txt[] = {
331 static const struct soc_enum da7210_hp_mode_sel =
335 static int da7210_put_alc_sw(
struct snd_kcontrol *kcontrol,
340 if (ucontrol->
value.integer.value[0]) {
344 "Disable noise suppression to enable ALC\n");
358 static int da7210_put_noise_sup_sw(
struct snd_kcontrol *kcontrol,
364 if (ucontrol->
value.integer.value[0]) {
401 0, 0x3F, 0, hp_out_tlv),
404 0, 0x77, 1, dac_gain_tlv),
407 0, 0x3f, 0, lineout_vol_tlv),
413 0, 0x5, 0, mic_vol_tlv),
416 0, 0x3f, 0, aux1_vol_tlv),
438 1, adc_eq_master_gain_tlv),
451 SOC_ENUM(
"DAC HPF Cutoff", da7210_dac_hpf_cutoff),
453 SOC_ENUM(
"DAC Voice Cutoff", da7210_dac_vf_cutoff),
456 SOC_ENUM(
"ADC HPF Cutoff", da7210_adc_hpf_cutoff),
458 SOC_ENUM(
"ADC Voice Cutoff", da7210_adc_vf_cutoff),
473 SOC_ENUM(
"Headphone Class", da7210_hp_mode_sel),
564 &da7210_dapm_inmixl_controls[0],
568 &da7210_dapm_inmixr_controls[0],
582 &da7210_dapm_outmixl_controls[0],
586 &da7210_dapm_outmixr_controls[0],
590 &da7210_dapm_monomix_controls[0],
615 {
"Mic Left",
NULL,
"MICL"},
616 {
"Mic Right",
NULL,
"MICR"},
617 {
"Aux1 Left",
NULL,
"AUX1L"},
618 {
"Aux1 Right",
NULL,
"AUX1R"},
619 {
"Aux2 Mono",
NULL,
"AUX2"},
621 {
"In Mixer Left",
"Mic Left Switch",
"Mic Left"},
622 {
"In Mixer Left",
"Mic Right Switch",
"Mic Right"},
623 {
"In Mixer Left",
"Aux1 Left Switch",
"Aux1 Left"},
624 {
"In Mixer Left",
"Aux2 Switch",
"Aux2 Mono"},
625 {
"In Mixer Left",
"Outmix Left Switch",
"Out Mixer Left"},
627 {
"In Mixer Right",
"Mic Right Switch",
"Mic Right"},
628 {
"In Mixer Right",
"Mic Left Switch",
"Mic Left"},
629 {
"In Mixer Right",
"Aux1 Right Switch",
"Aux1 Right"},
630 {
"In Mixer Right",
"Aux2 Switch",
"Aux2 Mono"},
631 {
"In Mixer Right",
"Outmix Right Switch",
"Out Mixer Right"},
633 {
"INPGA Left",
NULL,
"In Mixer Left"},
634 {
"ADC Left",
NULL,
"INPGA Left"},
636 {
"INPGA Right",
NULL,
"In Mixer Right"},
637 {
"ADC Right",
NULL,
"INPGA Right"},
640 {
"Out Mixer Left",
"Aux1 Left Switch",
"Aux1 Left"},
641 {
"Out Mixer Left",
"Aux2 Switch",
"Aux2 Mono"},
642 {
"Out Mixer Left",
"INPGA Left Switch",
"INPGA Left"},
643 {
"Out Mixer Left",
"INPGA Right Switch",
"INPGA Right"},
644 {
"Out Mixer Left",
"DAC Left Switch",
"DAC Left"},
646 {
"Out Mixer Right",
"Aux1 Right Switch",
"Aux1 Right"},
647 {
"Out Mixer Right",
"Aux2 Switch",
"Aux2 Mono"},
648 {
"Out Mixer Right",
"INPGA Right Switch",
"INPGA Right"},
649 {
"Out Mixer Right",
"INPGA Left Switch",
"INPGA Left"},
650 {
"Out Mixer Right",
"DAC Right Switch",
"DAC Right"},
652 {
"Mono Mixer",
"INPGA Right Switch",
"INPGA Right"},
653 {
"Mono Mixer",
"INPGA Left Switch",
"INPGA Left"},
654 {
"Mono Mixer",
"Outmix Right Switch",
"Out Mixer Right"},
655 {
"Mono Mixer",
"Outmix Left Switch",
"Out Mixer Left"},
657 {
"OUTPGA Left Enable",
NULL,
"Out Mixer Left"},
658 {
"OUTPGA Right Enable",
NULL,
"Out Mixer Right"},
660 {
"Out1 Left",
NULL,
"OUTPGA Left Enable"},
661 {
"OUT1L",
NULL,
"Out1 Left"},
663 {
"Out1 Right",
NULL,
"OUTPGA Right Enable"},
664 {
"OUT1R",
NULL,
"Out1 Right"},
666 {
"Headphone Left",
NULL,
"OUTPGA Left Enable"},
667 {
"HPL",
NULL,
"Headphone Left"},
669 {
"Headphone Right",
NULL,
"OUTPGA Right Enable"},
670 {
"HPR",
NULL,
"Headphone Right"},
672 {
"Out2 Mono",
NULL,
"Mono Mixer"},
673 {
"OUT2",
NULL,
"Out2 Mono"},
683 static struct reg_default da7210_reg_defaults[] = {
736 static bool da7210_readable_register(
struct device *
dev,
unsigned int reg)
749 static bool da7210_volatile_register(
struct device *dev,
768 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
882 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
948 #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
949 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
951 static int da7210_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
952 int clk_id,
unsigned int freq,
int dir)
955 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
970 dev_err(codec_dai->
dev,
"Unsupported MCLK value %d\n",
976 dev_err(codec_dai->
dev,
"Unknown clock source %d\n", clk_id);
992 static int da7210_set_dai_pll(
struct snd_soc_dai *codec_dai,
int pll_id,
993 int source,
unsigned int fref,
unsigned int fout)
996 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
998 u8 pll_div1, pll_div2, pll_div3,
cnt;
1005 for (cnt = 0; cnt <
ARRAY_SIZE(da7210_pll_div); cnt++) {
1007 if ((fref == da7210_pll_div[cnt].fref) &&
1009 (fout == da7210_pll_div[cnt].fout)) {
1011 pll_div1 = da7210_pll_div[
cnt].
div1;
1012 pll_div2 = da7210_pll_div[
cnt].
div2;
1013 pll_div3 = da7210_pll_div[
cnt].
div3;
1036 dev_err(codec_dai->
dev,
"Unsupported PLL input frequency %d\n", fref);
1042 .hw_params = da7210_hw_params,
1043 .set_fmt = da7210_set_dai_fmt,
1044 .set_sysclk = da7210_set_dai_sysclk,
1045 .set_pll = da7210_set_dai_pll,
1046 .digital_mute = da7210_mute,
1050 .name =
"da7210-hifi",
1053 .stream_name =
"Playback",
1061 .stream_name =
"Capture",
1067 .ops = &da7210_dai_ops,
1068 .symmetric_rates = 1,
1073 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
1081 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
1180 .probe = da7210_probe,
1182 .controls = da7210_snd_controls,
1183 .num_controls =
ARRAY_SIZE(da7210_snd_controls),
1185 .dapm_widgets = da7210_dapm_widgets,
1186 .num_dapm_widgets =
ARRAY_SIZE(da7210_dapm_widgets),
1187 .dapm_routes = da7210_audio_map,
1188 .num_dapm_routes =
ARRAY_SIZE(da7210_audio_map),
1191 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1193 static struct reg_default da7210_regmap_i2c_patch[] = {
1210 static const struct regmap_config da7210_regmap_config_i2c = {
1214 .reg_defaults = da7210_reg_defaults,
1215 .num_reg_defaults =
ARRAY_SIZE(da7210_reg_defaults),
1216 .volatile_reg = da7210_volatile_register,
1217 .readable_reg = da7210_readable_register,
1232 i2c_set_clientdata(i2c, da7210);
1235 if (IS_ERR(da7210->
regmap)) {
1236 ret = PTR_ERR(da7210->
regmap);
1237 dev_err(&i2c->
dev,
"regmap_init() failed: %d\n", ret);
1244 dev_warn(&i2c->
dev,
"Failed to apply regmap patch: %d\n", ret);
1247 &soc_codec_dev_da7210, &da7210_dai, 1);
1249 dev_err(&i2c->
dev,
"Failed to register codec: %d\n", ret);
1262 struct da7210_priv *da7210 = i2c_get_clientdata(client);
1276 static struct i2c_driver da7210_i2c_driver = {
1281 .probe = da7210_i2c_probe,
1283 .id_table = da7210_i2c_id,
1287 #if defined(CONFIG_SPI_MASTER)
1289 static struct reg_default da7210_regmap_spi_patch[] = {
1313 static const struct regmap_config da7210_regmap_config_spi = {
1316 .read_flag_mask = 0x01,
1317 .write_flag_mask = 0x00,
1319 .reg_defaults = da7210_reg_defaults,
1320 .num_reg_defaults =
ARRAY_SIZE(da7210_reg_defaults),
1321 .volatile_reg = da7210_volatile_register,
1322 .readable_reg = da7210_readable_register,
1336 spi_set_drvdata(spi, da7210);
1338 if (IS_ERR(da7210->
regmap)) {
1339 ret = PTR_ERR(da7210->
regmap);
1340 dev_err(&spi->
dev,
"Failed to register regmap: %d\n", ret);
1347 dev_warn(&spi->
dev,
"Failed to apply regmap patch: %d\n", ret);
1350 &soc_codec_dev_da7210, &da7210_dai, 1);
1364 struct da7210_priv *da7210 = spi_get_drvdata(spi);
1370 static struct spi_driver da7210_spi_driver = {
1375 .probe = da7210_spi_probe,
1380 static int __init da7210_modinit(
void)
1383 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1384 ret = i2c_add_driver(&da7210_i2c_driver);
1386 #if defined(CONFIG_SPI_MASTER)
1397 static void __exit da7210_exit(
void)
1399 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1402 #if defined(CONFIG_SPI_MASTER)
1403 spi_unregister_driver(&da7210_spi_driver);