2 * rt5625.c -- RT5625 ALSA SoC audio codec driver
4 * Copyright 2011 Realtek Semiconductor Corp.
5 * Author: Johnny Hsu <johnnyhsu@realtek.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/init.h>
15 #include <linux/delay.h>
17 #include <linux/i2c.h>
18 #include <linux/platform_device.h>
19 #include <linux/spi/spi.h>
20 #include <linux/of_gpio.h>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/pcm_params.h>
24 #include <sound/soc.h>
25 #include <sound/soc-dapm.h>
26 #include <sound/initval.h>
27 #include <sound/tlv.h>
28 #include <linux/gpio.h>
31 #define INVALID_GPIO -1
35 #include <linux/proc_fs.h>
36 #include <linux/seq_file.h>
37 #include <linux/vmalloc.h>
38 char debug_write_read = 0;
42 #define DBG(x...) printk(KERN_INFO x)
44 #define DBG(x...) do { } while (0)
47 static struct snd_soc_codec *rt5625_codec;
49 #define RT5625_REG_RW 1 /* for debug */
50 //#define RT5625_DEMO 1 /* only for demo; please remove it */
52 #define RT5625_F_SMT_PHO
53 #define RT5625_PLY_BIT 0
54 #define RT5625_PLY_MASK (0x1)
55 #define RT5625_REC_BIT 1
56 #define RT5625_REC_MASK (0x1 << RT5625_REC_BIT)
57 #define RT5625_3G_BIT 2
58 #define RT5625_3G_MASK (0x1 << RT5625_3G_BIT)
59 #define RT5625_BT_BIT 3
60 #define RT5625_BT_MASK (0x1 << RT5625_BT_BIT)
61 #define RT5625_VOIP_BIT 4
62 #define RT5625_VOIP_MASK (0x1 << RT5625_VOIP_BIT)
65 unsigned int stereo_sysclk;
66 unsigned int voice_sysclk;
73 #ifdef RT5625_F_SMT_PHO
74 int app_bmp;/* bit{0, 1, 2, 3, 4} = {play, rec, 3g, bt, voip} */
84 #ifdef RT5625_F_SMT_PHO
85 static u16 rt5625_voip_back[][2] = {
86 {RT5625_VODSP_PDM_CTL, 0x0000},
87 {RT5625_F_DAC_ADC_VDAC, 0x0000},
89 #define RT5625_VOIP_BK_NUM \
90 (sizeof(rt5625_voip_back) / sizeof(rt5625_voip_back[0]))
94 struct rt5625_init_reg {
99 static struct rt5625_init_reg init_list[] = {
100 {RT5625_HP_OUT_VOL , 0x8888}, //default is -12db
101 {RT5625_SPK_OUT_VOL , 0x8080}, //default is 0db
102 {RT5625_PHONEIN_VOL , 0xe800}, //phone differential
103 {RT5625_DAC_MIC_CTRL , 0xee01}, //DAC to hpmixer & spkmixer
104 {RT5625_OUTMIX_CTRL , 0x2bc8}, //spk from spkmixer; hp from hpmixer; aux from monomixer; classAB
105 {RT5625_ADC_REC_MIXER , 0x1f1f}, //record source from mic1 & mic2
106 {RT5625_GEN_CTRL1 , 0x0c08}, //speaker vdd ratio is 1; 1.25VDD ratio
108 #define RT5625_INIT_REG_LEN ARRAY_SIZE(init_list)
110 static int rt5625_reg_init(struct snd_soc_codec *codec)
113 for (i = 0; i < RT5625_INIT_REG_LEN; i++)
114 snd_soc_write(codec, init_list[i].reg, init_list[i].val);
119 static const u16 rt5625_reg[0x80] = {
120 [RT5625_RESET] = 0x59b4,
121 [RT5625_SPK_OUT_VOL] = 0x8080,
122 [RT5625_HP_OUT_VOL] = 0x8080,
123 [RT5625_AUX_OUT_VOL] = 0x8080,
124 [RT5625_PHONEIN_VOL] = 0xc800,
125 [RT5625_LINE_IN_VOL] = 0xe808,
126 [RT5625_DAC_VOL] = 0x1010,
127 [RT5625_MIC_VOL] = 0x0808,
128 [RT5625_DAC_MIC_CTRL] = 0xee0f,
129 [RT5625_ADC_REC_GAIN] = 0xcbcb,
130 [RT5625_ADC_REC_MIXER] = 0x7f7f,
131 [RT5625_VDAC_OUT_VOL] = 0xe010,
132 [RT5625_OUTMIX_CTRL] = 0x8008,
133 [RT5625_VODSP_CTL] = 0x2007,
134 [RT5625_DMIC_CTRL] = 0x00c0,
135 [RT5625_PD_CTRL] = 0xef00,
136 [RT5625_GEN_CTRL1] = 0x0c0a,
137 [RT5625_LDO_CTRL] = 0x0029,
138 [RT5625_GPIO_CONFIG] = 0xbe3e,
139 [RT5625_GPIO_POLAR] = 0x3e3e,
140 [RT5625_GPIO_STATUS] = 0x803a,
141 [RT5625_SOFT_VOL_CTRL] = 0x0009,
142 [RT5625_DAC_CLK_CTRL1] = 0x3075,
143 [RT5625_DAC_CLK_CTRL2] = 0x1010,
144 [RT5625_VDAC_CLK_CTRL1] = 0x3110,
145 [RT5625_PS_CTRL] = 0x0553,
146 [RT5625_VENDOR_ID1] = 0x10ec,
147 [RT5625_VENDOR_ID2] = 0x5c02,
150 rt5625_dsp_reg rt5625_dsp_init[] = {
187 #define RT5625_DSP_INIT_NUM ARRAY_SIZE(rt5625_dsp_init)
189 static int rt5625_volatile_register(
190 struct snd_soc_codec *codec, unsigned int reg)
195 case RT5625_GPIO_STATUS:
196 case RT5625_OTC_STATUS:
197 case RT5625_PRIV_DATA:
199 case RT5625_DSP_DATA:
201 case RT5625_VENDOR_ID1:
202 case RT5625_VENDOR_ID2:
209 static int rt5625_readable_register(
210 struct snd_soc_codec *codec, unsigned int reg)
214 case RT5625_SPK_OUT_VOL:
215 case RT5625_HP_OUT_VOL:
216 case RT5625_AUX_OUT_VOL:
217 case RT5625_PHONEIN_VOL:
218 case RT5625_LINE_IN_VOL:
221 case RT5625_DAC_MIC_CTRL:
222 case RT5625_ADC_REC_GAIN:
223 case RT5625_ADC_REC_MIXER:
224 case RT5625_VDAC_OUT_VOL:
225 case RT5625_VODSP_PDM_CTL:
226 case RT5625_OUTMIX_CTRL:
227 case RT5625_VODSP_CTL:
228 case RT5625_MIC_CTRL:
229 case RT5625_DMIC_CTRL:
231 case RT5625_F_DAC_ADC_VDAC:
232 case RT5625_SDP_CTRL:
233 case RT5625_EXT_SDP_CTRL:
234 case RT5625_PWR_ADD1:
235 case RT5625_PWR_ADD2:
236 case RT5625_PWR_ADD3:
237 case RT5625_GEN_CTRL1:
238 case RT5625_GEN_CTRL2:
239 case RT5625_PLL_CTRL:
240 case RT5625_PLL2_CTRL:
241 case RT5625_LDO_CTRL:
242 case RT5625_GPIO_CONFIG:
243 case RT5625_GPIO_POLAR:
244 case RT5625_GPIO_STICKY:
245 case RT5625_GPIO_WAKEUP:
246 case RT5625_GPIO_STATUS:
247 case RT5625_GPIO_SHARING:
248 case RT5625_OTC_STATUS:
249 case RT5625_SOFT_VOL_CTRL:
250 case RT5625_GPIO_OUT_CTRL:
251 case RT5625_MISC_CTRL:
252 case RT5625_DAC_CLK_CTRL1:
253 case RT5625_DAC_CLK_CTRL2:
254 case RT5625_VDAC_CLK_CTRL1:
256 case RT5625_PRIV_INDEX:
257 case RT5625_PRIV_DATA:
259 case RT5625_DSP_ADDR:
260 case RT5625_DSP_DATA:
262 case RT5625_VENDOR_ID1:
263 case RT5625_VENDOR_ID2:
270 static unsigned int rt5625_read(struct snd_soc_codec *codec,
275 val = codec->hw_read(codec, reg);
279 static int rt5625_write(struct snd_soc_codec *codec, unsigned int reg,
286 data[1] = (value >> 8) & 0xff;
287 data[2] = value & 0xff;
289 val = codec->hw_write(codec->control_data, data, 3);
293 static int rt5625_reset(struct snd_soc_codec *codec)
295 return snd_soc_write(codec, RT5625_RESET, 0);
299 * rt5625_index_write - Write private register.
300 * @codec: SoC audio codec device.
301 * @reg: Private register index.
302 * @value: Private register Data.
304 * Modify private register for advanced setting. It can be written through
305 * private index (0x6a) and data (0x6c) register.
307 * Returns 0 for success or negative error code.
309 static int rt5625_index_write(struct snd_soc_codec *codec,
310 unsigned int reg, unsigned int value)
314 ret = snd_soc_write(codec, RT5625_PRIV_INDEX, reg);
316 dev_err(codec->dev, "Failed to set private addr: %d\n", ret);
319 ret = snd_soc_write(codec, RT5625_PRIV_DATA, value);
321 dev_err(codec->dev, "Failed to set private value: %d\n", ret);
331 * rt5625_index_read - Read private register.
332 * @codec: SoC audio codec device.
333 * @reg: Private register index.
335 * Read advanced setting from private register. It can be read through
336 * private index (0x6a) and data (0x6c) register.
338 * Returns private register value or negative error code.
340 static unsigned int rt5625_index_read(
341 struct snd_soc_codec *codec, unsigned int reg)
345 ret = snd_soc_write(codec, RT5625_PRIV_INDEX, reg);
347 dev_err(codec->dev, "Failed to set private addr: %d\n", ret);
350 return snd_soc_read(codec, RT5625_PRIV_DATA);
354 * rt5625_index_update_bits - update private register bits
355 * @codec: Audio codec
356 * @reg: Private register index.
357 * @mask: Register mask
360 * Writes new register value.
362 * Returns 1 for change, 0 for no change, or negative error code.
364 static int rt5625_index_update_bits(struct snd_soc_codec *codec,
365 unsigned int reg, unsigned int mask, unsigned int value)
367 unsigned int old, new;
370 ret = rt5625_index_read(codec, reg);
372 dev_err(codec->dev, "Failed to read private reg: %d\n", ret);
377 new = (old & ~mask) | (value & mask);
380 ret = rt5625_index_write(codec, reg, new);
383 "Failed to write private reg: %d\n", ret);
394 * rt5625_dsp_done - Wait until DSP is ready.
395 * @codec: SoC Audio Codec device.
397 * To check voice DSP status and confirm it's ready for next work.
399 * Returns 0 for success or negative error code.
401 static int rt5625_dsp_done(struct snd_soc_codec *codec)
403 unsigned int count = 0, dsp_val;
405 dsp_val = snd_soc_read(codec, RT5625_DSP_CMD);
406 while(dsp_val & RT5625_DSP_BUSY_MASK) {
409 dsp_val = snd_soc_read(codec, RT5625_DSP_CMD);
417 * rt5625_dsp_write - Write DSP register.
418 * @codec: SoC audio codec device.
419 * @reg: DSP register index.
420 * @value: DSP register Data.
422 * Modify voice DSP register for sound effect. The DSP can be controlled
423 * through DSP addr (0x70), data (0x72) and cmd (0x74) register. It has
424 * to wait until the DSP is ready.
426 * Returns 0 for success or negative error code.
428 static int rt5625_dsp_write(struct snd_soc_codec *codec,
429 unsigned int reg, unsigned int value)
433 ret = rt5625_dsp_done(codec);
435 dev_err(codec->dev, "DSP is busy: %d\n", ret);
438 ret = snd_soc_write(codec, RT5625_DSP_ADDR, reg);
440 dev_err(codec->dev, "Failed to write DSP addr reg: %d\n", ret);
443 ret = snd_soc_write(codec, RT5625_DSP_DATA, value);
445 dev_err(codec->dev, "Failed to write DSP data reg: %d\n", ret);
448 ret = snd_soc_write(codec, RT5625_DSP_CMD,
449 RT5625_DSP_W_EN | RT5625_DSP_CMD_MW);
451 dev_err(codec->dev, "Failed to write DSP cmd reg: %d\n", ret);
462 * rt5625_dsp_read - Read DSP register.
463 * @codec: SoC audio codec device.
464 * @reg: DSP register index.
466 * Read DSP setting value from voice DSP. The DSP can be controlled
467 * through DSP addr (0x70), data (0x72) and cmd (0x74) register. Each
468 * command has to wait until the DSP is ready.
470 * Returns DSP register value or negative error code.
472 static unsigned int rt5625_dsp_read(
473 struct snd_soc_codec *codec, unsigned int reg)
475 unsigned int val_h, val_l;
478 ret = rt5625_dsp_done(codec);
480 dev_err(codec->dev, "DSP is busy: %d\n", ret);
483 ret = snd_soc_write(codec, RT5625_DSP_ADDR, reg);
485 dev_err(codec->dev, "Failed to write DSP addr reg: %d\n", ret);
488 ret = snd_soc_write(codec, RT5625_DSP_CMD,
489 RT5625_DSP_R_EN | RT5625_DSP_CMD_MR);
491 dev_err(codec->dev, "Failed to write DSP cmd reg: %d\n", ret);
495 /* Read DSP high byte data */
496 ret = rt5625_dsp_done(codec);
498 dev_err(codec->dev, "DSP is busy: %d\n", ret);
501 ret = snd_soc_write(codec, RT5625_DSP_ADDR, 0x26);
503 dev_err(codec->dev, "Failed to write DSP addr reg: %d\n", ret);
506 ret = snd_soc_write(codec, RT5625_DSP_CMD,
507 RT5625_DSP_R_EN | RT5625_DSP_CMD_RR);
509 dev_err(codec->dev, "Failed to write DSP cmd reg: %d\n", ret);
512 ret = rt5625_dsp_done(codec);
514 dev_err(codec->dev, "DSP is busy: %d\n", ret);
517 ret = snd_soc_read(codec, RT5625_DSP_DATA);
519 dev_err(codec->dev, "Failed to read DSP data reg: %d\n", ret);
524 /* Read DSP low byte data */
525 ret = snd_soc_write(codec, RT5625_DSP_ADDR, 0x25);
527 dev_err(codec->dev, "Failed to write DSP addr reg: %d\n", ret);
530 ret = snd_soc_write(codec, RT5625_DSP_CMD,
531 RT5625_DSP_R_EN | RT5625_DSP_CMD_RR);
533 dev_err(codec->dev, "Failed to write DSP cmd reg: %d\n", ret);
536 ret = rt5625_dsp_done(codec);
538 dev_err(codec->dev, "DSP is busy: %d\n", ret);
541 ret = snd_soc_read(codec, RT5625_DSP_DATA);
543 dev_err(codec->dev, "Failed to read DSP data reg: %d\n", ret);
548 return ((val_h & 0xff) << 8) |(val_l & 0xff);
554 static const char *rt5625_spk_ctr_sel[] = {"Disable", "Enable"};
556 /* ADCR function select */
557 static const char *adcr_fun_sel[] = {
558 "Stereo ADC", "Voice ADC", "VoDSP", "PDM Slave"};
560 static const struct soc_enum adcr_fun_sel_enum =
561 SOC_ENUM_SINGLE(RT5625_F_DAC_ADC_VDAC, RT5625_ADCR_F_SFT,
562 ARRAY_SIZE(adcr_fun_sel), adcr_fun_sel);
564 /* ADCL function select */
565 static const char *adcl_fun_sel[] = {"Stereo ADC", "VoDSP"};
567 static const struct soc_enum adcl_fun_sel_enum =
568 SOC_ENUM_SINGLE(RT5625_F_DAC_ADC_VDAC, RT5625_ADCL_F_SFT,
569 ARRAY_SIZE(adcl_fun_sel), adcl_fun_sel);
572 static const char *rt5625_aec_fun[] = {"Disable", "Enable"};
574 static const SOC_ENUM_SINGLE_DECL(rt5625_aec_fun_enum, 0, 0, rt5625_aec_fun);
576 static const char *rt5625_dsp_lrck[] = {"8KHz", "16KHz"};
578 static const SOC_ENUM_SINGLE_DECL(rt5625_dsp_lrck_enum,
579 RT5625_VODSP_CTL, RT5625_DSP_LRCK_SFT, rt5625_dsp_lrck);
581 static const char *rt5625_bp_ctrl[] = {"Bypass", "Normal"};
583 static const SOC_ENUM_SINGLE_DECL(rt5625_bp_ctrl_enum,
584 RT5625_VODSP_CTL, RT5625_DSP_BP_SFT, rt5625_bp_ctrl);
586 static const char *rt5625_pd_ctrl[] = {"Power down", "Normal"};
588 static const SOC_ENUM_SINGLE_DECL(rt5625_pd_ctrl_enum,
589 RT5625_VODSP_CTL, RT5625_DSP_PD_SFT, rt5625_pd_ctrl);
591 static const char *rt5625_rst_ctrl[] = {"Reset", "Normal"};
593 static const SOC_ENUM_SINGLE_DECL(rt5625_rst_ctrl_enum,
594 RT5625_VODSP_CTL, RT5625_DSP_RST_SFT, rt5625_rst_ctrl);
596 static const char *rt5625_spk_out[] = {"Class AB", "Class D"};
598 static const SOC_ENUM_SINGLE_DECL(rt5625_spk_out_enum,
599 RT5625_OUTMIX_CTRL, RT5625_SPK_T_SFT, rt5625_spk_out);
601 static const char *rt5625_spkl_src[] = {"LPRN", "LPRP", "LPLN", "MM"};
603 static const SOC_ENUM_SINGLE_DECL(rt5625_spkl_src_enum,
604 RT5625_OUTMIX_CTRL, RT5625_SPKN_S_SFT, rt5625_spkl_src);
606 static const char *rt5625_spkamp_ratio[] = {"2.25 Vdd", "2.00 Vdd",
607 "1.75 Vdd", "1.50 Vdd", "1.25 Vdd", "1.00 Vdd"};
609 static const SOC_ENUM_SINGLE_DECL(rt5625_spkamp_ratio_enum,
610 RT5625_GEN_CTRL1, RT5625_SPK_R_SFT, rt5625_spkamp_ratio);
612 static const char *rt5625_Pin_mode[] = {"IRQ Out", "GPIO enable", "Reserved", "VoDSP bypass"};
613 static const char *rt5625_Pin_configuration[] = {"Output", "Input"};
614 static const char *rt5625_Pin_level[] = {"Low", "High"};
616 /* Output/Input Mode */
617 //static const char *rt5625_auxout_mode[] = {"Differential", "Single ended"};
619 //static const SOC_ENUM_SINGLE_DECL(rt5625_auxout_mode_enum,
620 // RT5625_OUTMIX_CTRL, RT5625_AUXOUT_MODE_SFT, rt5625_auxout_mode);
622 //static const char *rt5625_input_mode[] = {"Single ended", "Differential"};
624 //static const SOC_ENUM_SINGLE_DECL(rt5625_phone_mode_enum,
625 // RT5625_PHONEIN_VOL, RT5625_PHO_DIFF_SFT, rt5625_input_mode);
627 //static const SOC_ENUM_SINGLE_DECL(rt5625_mic1_mode_enum,
628 // RT5625_MIC_VOL, RT5625_MIC1_DIFF_SFT, rt5625_input_mode);
630 //static const SOC_ENUM_SINGLE_DECL(rt5625_mic2_mode_enum,
631 // RT5625_MIC_VOL, RT5625_MIC2_DIFF_SFT, rt5625_input_mode);
633 static const struct soc_enum rt5625_gpio2_enum[] = {
634 SOC_ENUM_SINGLE(RT5625_GPIO_SHARING, 0, 4, rt5625_Pin_mode), /*0*/
635 SOC_ENUM_SINGLE(RT5625_GPIO_CONFIG, 2, 2, rt5625_Pin_configuration),/*1*/
636 SOC_ENUM_SINGLE(RT5625_GPIO_OUT_CTRL, 2, 2, rt5625_Pin_level), /*2*/
639 static int rt5625_adcr_fun_sel_put(struct snd_kcontrol *kcontrol,
640 struct snd_ctl_elem_value *ucontrol)
642 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
643 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
644 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
645 unsigned int val, mask, bitmask;
647 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
649 if (ucontrol->value.enumerated.item[0] > e->max - 1)
651 val = ucontrol->value.enumerated.item[0] << e->shift_l;
652 mask = (bitmask - 1) << e->shift_l;
654 snd_soc_update_bits(codec, RT5625_PD_CTRL,
655 RT5625_PWR_PR0, RT5625_PWR_PR0);
656 if ((rt5625->app_bmp & RT5625_3G_MASK) &&
657 rt5625->vodsp_fun == RT5625_AEC_EN) {
658 snd_soc_update_bits(codec, e->reg, mask, RT5625_ADCR_F_PDM);
659 } else if (rt5625->app_bmp & RT5625_VOIP_MASK &&
660 rt5625->vodsp_fun == RT5625_AEC_EN) {
661 snd_soc_update_bits(codec, e->reg, mask, RT5625_ADCR_F_PDM);
662 } else if (rt5625->app_bmp & RT5625_BT_MASK) {
663 snd_soc_update_bits(codec, e->reg, mask, RT5625_ADCR_F_VADC);
665 snd_soc_update_bits(codec, e->reg, mask, val);
667 snd_soc_update_bits(codec, RT5625_PD_CTRL, RT5625_PWR_PR0, 0);
672 static int rt5625_adcl_fun_sel_put(struct snd_kcontrol *kcontrol,
673 struct snd_ctl_elem_value *ucontrol)
675 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
676 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
677 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
678 unsigned int val, mask, bitmask;
680 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
682 if (ucontrol->value.enumerated.item[0] > e->max - 1)
684 val = ucontrol->value.enumerated.item[0] << e->shift_l;
685 mask = (bitmask - 1) << e->shift_l;
687 snd_soc_update_bits(codec, RT5625_PD_CTRL,
688 RT5625_PWR_PR0, RT5625_PWR_PR0);
689 if ((rt5625->app_bmp & RT5625_3G_MASK) &&
690 rt5625->vodsp_fun == RT5625_AEC_EN) {
691 snd_soc_update_bits(codec, e->reg, mask, RT5625_ADCL_F_DSP);
693 snd_soc_update_bits(codec, e->reg, mask, val);
695 snd_soc_update_bits(codec, RT5625_PD_CTRL, RT5625_PWR_PR0, 0);
700 static int rt5625_init_vodsp_aec(struct snd_soc_codec *codec)
704 /*disable LDO power*/
705 snd_soc_update_bits(codec, RT5625_LDO_CTRL,
706 RT5625_LDO_MASK, RT5625_LDO_DIS);
708 snd_soc_update_bits(codec, RT5625_VODSP_CTL,
709 RT5625_DSP_PD_MASK, RT5625_DSP_PD_NOR);
710 /*enable LDO power and set output voltage to 1.2V*/
711 snd_soc_update_bits(codec, RT5625_LDO_CTRL,
712 RT5625_LDO_MASK | RT5625_LDO_VC_MASK,
713 RT5625_LDO_EN | RT5625_LDO_VC_1_20V);
715 /*enable power of VODSP I2C interface*/
716 snd_soc_update_bits(codec, RT5625_PWR_ADD3, RT5625_P_DSP_IF |
717 RT5625_P_DSP_I2C, RT5625_P_DSP_IF | RT5625_P_DSP_I2C);
720 snd_soc_update_bits(codec, RT5625_VODSP_CTL,
721 RT5625_DSP_RST_MASK, RT5625_DSP_RST_EN);
723 /*set VODSP to non-reset status*/
724 snd_soc_update_bits(codec, RT5625_VODSP_CTL,
725 RT5625_DSP_RST_MASK, RT5625_DSP_RST_NOR);
728 /*initize AEC paramter*/
729 for(i = 0; i < RT5625_DSP_INIT_NUM; i++) {
730 ret = rt5625_dsp_write(codec, rt5625_dsp_init[i].index,
731 rt5625_dsp_init[i].value);
736 //printk("[DSP poweron] 0x%04x: 0x%04x\n", 0x230C, rt5625_dsp_read(codec, 0x230C));
741 static int rt5625_aec_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
743 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
744 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
746 ucontrol->value.integer.value[0] = rt5625->vodsp_fun;
751 static int rt5625_aec_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
753 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
754 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
756 if(ucontrol->value.integer.value[0] == rt5625->vodsp_fun)
758 rt5625->vodsp_fun = ucontrol->value.integer.value[0];
760 switch(rt5625->vodsp_fun) {
764 if (!(rt5625->app_bmp & RT5625_3G_MASK) ||
765 ((rt5625->app_bmp & RT5625_3G_MASK) && rt5625->headset)) {
766 snd_soc_update_bits(codec, RT5625_VODSP_CTL,
767 RT5625_DSP_PD_MASK, RT5625_DSP_PD_EN);
768 snd_soc_update_bits(codec, RT5625_PWR_ADD3,
769 RT5625_P_DSP_IF | RT5625_P_DSP_I2C, 0);
770 snd_soc_update_bits(codec, RT5625_LDO_CTRL,
771 RT5625_LDO_MASK, RT5625_LDO_DIS);
781 #ifdef RT5625_F_SMT_PHO
782 static int rt5625_app_get(struct snd_kcontrol *kcontrol,
783 struct snd_ctl_elem_value *ucontrol)
785 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
786 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
788 pr_info("App status: %x\n", rt5625->app_bmp);
793 static int rt5625_cap_voip_chk_put(struct snd_kcontrol *kcontrol,
794 struct snd_ctl_elem_value *ucontrol)
796 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
797 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
800 /* VoIP start up if record & playback all turn on, or AEC *
801 * is disabled. otherwise, cheat dapm. */
802 if ((rt5625->app_bmp & RT5625_REC_MASK) == 0 ||
803 (rt5625->app_bmp & RT5625_PLY_MASK) == 0) {
804 /* backup registers for voip routing */
805 for(i = 0; i < RT5625_VOIP_BK_NUM; i++)
806 rt5625_voip_back[i][1] =
807 snd_soc_read(codec, rt5625_voip_back[i][0]);
809 snd_soc_update_bits(codec, RT5625_VODSP_PDM_CTL,
810 RT5625_REC_IIS_S_MASK, RT5625_REC_IIS_S_SRC2);
814 if (rt5625->headset) {
815 /* backup registers for voip routing */
816 for(i = 0; i < RT5625_VOIP_BK_NUM; i++)
817 rt5625_voip_back[i][1] =
818 snd_soc_read(codec, rt5625_voip_back[i][0]);
820 snd_soc_update_bits(codec, RT5625_VODSP_PDM_CTL,
821 RT5625_REC_IIS_S_MASK, RT5625_REC_IIS_S_SRC2);
823 rt5625->vodsp_fun = RT5625_AEC_EN;
825 upd = (rt5625->app_bmp & ~RT5625_VOIP_MASK) |
826 (ucontrol->value.integer.value[0] << RT5625_VOIP_BIT);
827 if (rt5625->app_bmp != upd) {
828 rt5625->app_bmp = upd;
829 rt5625->app_bmp &= ~(RT5625_3G_MASK | RT5625_BT_MASK);
835 static int rt5625_cap_voip_put(struct snd_kcontrol *kcontrol,
836 struct snd_ctl_elem_value *ucontrol)
838 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
839 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
842 if (rt5625->app_bmp & RT5625_VOIP_MASK) {
843 if (rt5625->headset) {
844 snd_soc_update_bits(codec, RT5625_ADC_REC_MIXER,
845 RT5625_M_RM_L_MIC1 | RT5625_M_RM_R_MIC1 | RT5625_M_RM_L_PHO,
846 RT5625_M_RM_L_MIC1 | RT5625_M_RM_R_MIC1 | RT5625_M_RM_L_PHO);
847 /* recover all changes by voip */
848 for(i = 0; i < RT5625_VOIP_BK_NUM; i++)
849 snd_soc_write(codec, rt5625_voip_back[i][0],
850 rt5625_voip_back[i][1]);
851 snd_soc_update_bits(codec, RT5625_VODSP_PDM_CTL,
852 RT5625_SRC1_PWR | RT5625_SRC2_PWR, 0);
854 snd_soc_update_bits(codec, RT5625_ADC_REC_MIXER,
855 RT5625_M_RM_L_MIC1 | RT5625_M_RM_L_MIC2 | RT5625_M_RM_R_MIC2 | RT5625_M_RM_L_PHO,
856 RT5625_M_RM_L_MIC1 | RT5625_M_RM_L_MIC2 | RT5625_M_RM_R_MIC2 | RT5625_M_RM_L_PHO);
857 rt5625->vodsp_fun = RT5625_AEC_EN;
858 /* Mic1 & Mic2 boost 0db */
859 snd_soc_update_bits(codec, RT5625_MIC_CTRL,
860 RT5625_MIC1_BST_MASK | RT5625_MIC2_BST_MASK,
861 RT5625_MIC1_BST_BYPASS | RT5625_MIC2_BST_BYPASS);
862 /* Capture volume gain 9db */
863 snd_soc_update_bits(codec, RT5625_ADC_REC_GAIN,
864 RT5625_G_ADCL_MASK | RT5625_G_ADCR_MASK, (0x11 << 8 ) | 0x11);
867 /* recover all changes by voip */
868 for(i = 0; i < RT5625_VOIP_BK_NUM; i++)
869 snd_soc_write(codec, rt5625_voip_back[i][0],
870 rt5625_voip_back[i][1]);
871 snd_soc_update_bits(codec, RT5625_VODSP_PDM_CTL,
872 RT5625_SRC1_PWR | RT5625_SRC2_PWR, 0);
873 if (rt5625->app_bmp & RT5625_3G_MASK &&
874 rt5625->vodsp_fun == RT5625_AEC_EN) {
876 snd_soc_update_bits(codec, RT5625_MIC_CTRL,
877 RT5625_MIC1_BST_MASK, RT5625_MIC1_BST_BYPASS);
878 /* Capture volume gain 9db */
879 snd_soc_update_bits(codec, RT5625_ADC_REC_GAIN,
880 RT5625_G_ADCR_MASK, 0x11);
887 static int rt5625_hs_voip_chk_put(struct snd_kcontrol *kcontrol,
888 struct snd_ctl_elem_value *ucontrol)
890 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
891 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
894 rt5625->headset = true;
895 if ((rt5625->app_bmp & RT5625_REC_MASK) == 0 ||
896 (rt5625->app_bmp & RT5625_PLY_MASK) == 0) {
897 /* backup registers for voip routing */
898 for(i = 0; i < RT5625_VOIP_BK_NUM; i++)
899 rt5625_voip_back[i][1] =
900 snd_soc_read(codec, rt5625_voip_back[i][0]);
901 rt5625->vodsp_fun_bak = rt5625->vodsp_fun;
903 snd_soc_update_bits(codec, RT5625_VODSP_PDM_CTL,
904 RT5625_REC_IIS_S_MASK | RT5625_RXDP_PWR, RT5625_REC_IIS_S_ADC);
908 upd = (rt5625->app_bmp & ~RT5625_VOIP_MASK) |
909 (ucontrol->value.integer.value[0] << RT5625_VOIP_BIT);
910 if (rt5625->app_bmp != upd) {
911 rt5625->app_bmp = upd;
912 rt5625->app_bmp &= ~(RT5625_3G_MASK | RT5625_BT_MASK);
918 static int rt5625_hs_voip_put(struct snd_kcontrol *kcontrol,
919 struct snd_ctl_elem_value *ucontrol)
921 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
922 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
925 if (rt5625->app_bmp & RT5625_VOIP_MASK) {
926 snd_soc_update_bits(codec, RT5625_ADC_REC_MIXER,
927 RT5625_M_RM_R_MIC1 | RT5625_M_RM_L_PHO,
928 RT5625_M_RM_R_MIC1 | RT5625_M_RM_L_PHO);
929 /* Mic1 & Mic2 boost 0db */
930 snd_soc_update_bits(codec, RT5625_MIC_CTRL,
931 RT5625_MIC1_BST_MASK | RT5625_MIC2_BST_MASK,
932 RT5625_MIC1_BST_BYPASS | RT5625_MIC2_BST_BYPASS);
933 /* Capture volume gain 9db */
934 snd_soc_update_bits(codec, RT5625_ADC_REC_GAIN,
935 RT5625_G_ADCL_MASK | RT5625_G_ADCR_MASK, (0x11 << 8 ) | 0x11);
937 /* recover all changes by voip */
938 for(i = 0; i < RT5625_VOIP_BK_NUM; i++)
939 snd_soc_write(codec, rt5625_voip_back[i][0],
940 rt5625_voip_back[i][1]);
941 rt5625->vodsp_fun = rt5625->vodsp_fun_bak;
942 if ((rt5625->app_bmp & RT5625_3G_MASK) && rt5625->vodsp_fun == RT5625_AEC_EN) {
943 snd_soc_update_bits(codec, RT5625_F_DAC_ADC_VDAC,
944 RT5625_ADCR_F_MASK, RT5625_ADCR_F_PDM);
945 } else if (rt5625->app_bmp & RT5625_BT_MASK) {
946 snd_soc_update_bits(codec, RT5625_F_DAC_ADC_VDAC,
947 RT5625_ADCR_F_MASK, RT5625_ADCR_F_VADC);
949 snd_soc_update_bits(codec, RT5625_F_DAC_ADC_VDAC,
950 RT5625_ADCR_F_MASK, RT5625_ADCR_F_ADC);
957 static int rt5625_voip_chk_put(struct snd_kcontrol *kcontrol,
958 struct snd_ctl_elem_value *ucontrol)
960 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
961 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
964 rt5625->headset = false;
965 /* voip start-up if record is on-going; otherwise, cheat dapm */
966 if ((rt5625->app_bmp & RT5625_REC_MASK) == 0 ||
967 (rt5625->app_bmp & RT5625_PLY_MASK) == 0) {
968 /* backup registers for voip routing */
969 for(i = 0; i < RT5625_VOIP_BK_NUM; i++)
970 rt5625_voip_back[i][1] =
971 snd_soc_read(codec, rt5625_voip_back[i][0]);
972 rt5625->vodsp_fun_bak = rt5625->vodsp_fun;
974 snd_soc_update_bits(codec, RT5625_VODSP_PDM_CTL,
975 RT5625_RXDP_S_MASK | RT5625_REC_IIS_S_MASK | RT5625_RXDP_PWR,
976 RT5625_RXDP_S_SRC1 | RT5625_REC_IIS_S_SRC2);
980 upd = (rt5625->app_bmp & ~RT5625_VOIP_MASK) |
981 (ucontrol->value.integer.value[0] << RT5625_VOIP_BIT);
982 if (rt5625->app_bmp != upd) {
983 rt5625->app_bmp = upd;
984 rt5625->app_bmp &= ~(RT5625_3G_MASK | RT5625_BT_MASK);
990 static int rt5625_voip_put(struct snd_kcontrol *kcontrol,
991 struct snd_ctl_elem_value *ucontrol)
993 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
994 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
997 if (rt5625->app_bmp & RT5625_VOIP_MASK) {
998 snd_soc_update_bits(codec, RT5625_ADC_REC_MIXER,
999 RT5625_M_RM_R_MIC2 | RT5625_M_RM_L_PHO,
1000 RT5625_M_RM_R_MIC2 | RT5625_M_RM_L_PHO);
1001 /* Mic1 & Mic2 boost 0db */
1002 snd_soc_update_bits(codec, RT5625_MIC_CTRL,
1003 RT5625_MIC1_BST_MASK | RT5625_MIC2_BST_MASK,
1004 RT5625_MIC1_BST_BYPASS | RT5625_MIC2_BST_BYPASS);
1005 /* Capture volume gain 9db */
1006 snd_soc_update_bits(codec, RT5625_ADC_REC_GAIN,
1007 RT5625_G_ADCL_MASK | RT5625_G_ADCR_MASK, (0x11 << 8 ) | 0x11);
1009 /* recover all changes by voip */
1010 for(i = 0; i < RT5625_VOIP_BK_NUM; i++)
1011 snd_soc_write(codec, rt5625_voip_back[i][0],
1012 rt5625_voip_back[i][1]);
1013 rt5625->vodsp_fun = rt5625->vodsp_fun_bak;
1014 snd_soc_update_bits(codec, RT5625_VODSP_PDM_CTL,
1015 RT5625_SRC1_PWR | RT5625_SRC2_PWR, 0);
1016 if ((rt5625->app_bmp & RT5625_3G_MASK) && rt5625->vodsp_fun == RT5625_AEC_EN) {
1017 snd_soc_update_bits(codec, RT5625_F_DAC_ADC_VDAC,
1018 RT5625_ADCR_F_MASK, RT5625_ADCR_F_PDM);
1019 } else if (rt5625->app_bmp & RT5625_BT_MASK) {
1020 snd_soc_update_bits(codec, RT5625_F_DAC_ADC_VDAC,
1021 RT5625_ADCR_F_MASK, RT5625_ADCR_F_VADC);
1023 snd_soc_update_bits(codec, RT5625_F_DAC_ADC_VDAC,
1024 RT5625_ADCR_F_MASK, RT5625_ADCR_F_ADC);
1031 static int rt5625_voip_get(struct snd_kcontrol *kcontrol,
1032 struct snd_ctl_elem_value *ucontrol)
1034 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1035 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1037 ucontrol->value.integer.value[0] =
1038 (rt5625->app_bmp & RT5625_VOIP_MASK) >> RT5625_VOIP_BIT;
1043 static int rt5625_play_get(struct snd_kcontrol *kcontrol,
1044 struct snd_ctl_elem_value *ucontrol)
1046 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1047 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1049 ucontrol->value.integer.value[0] =
1050 (rt5625->app_bmp & RT5625_PLY_MASK) >> RT5625_PLY_BIT;
1055 static int rt5625_play_put(struct snd_kcontrol *kcontrol,
1056 struct snd_ctl_elem_value *ucontrol)
1058 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1059 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1062 upd = (rt5625->app_bmp & ~RT5625_PLY_MASK) |
1063 (ucontrol->value.integer.value[0] << RT5625_PLY_BIT);
1064 if (rt5625->app_bmp != upd)
1065 rt5625->app_bmp = upd;
1067 if (!(rt5625->app_bmp & RT5625_3G_MASK) ||
1068 ((rt5625->app_bmp & RT5625_3G_MASK) && rt5625->headset)) {
1069 snd_soc_update_bits(codec, RT5625_ADC_REC_MIXER,
1070 RT5625_M_RM_L_PHO, RT5625_M_RM_L_PHO);
1076 static int rt5625_rec_get(struct snd_kcontrol *kcontrol,
1077 struct snd_ctl_elem_value *ucontrol)
1079 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1080 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1082 ucontrol->value.integer.value[0] =
1083 (rt5625->app_bmp & RT5625_REC_MASK) >> RT5625_REC_BIT;
1088 static int rt5625_rec_put(struct snd_kcontrol *kcontrol,
1089 struct snd_ctl_elem_value *ucontrol)
1091 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1092 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1095 upd = (rt5625->app_bmp & ~RT5625_REC_MASK) |
1096 (ucontrol->value.integer.value[0] << RT5625_REC_BIT);
1097 if (rt5625->app_bmp != upd)
1098 rt5625->app_bmp = upd;
1100 if (!(rt5625->app_bmp & RT5625_3G_MASK) ||
1101 ((rt5625->app_bmp & RT5625_3G_MASK) && rt5625->headset)) {
1102 snd_soc_update_bits(codec, RT5625_ADC_REC_MIXER,
1103 RT5625_M_RM_L_PHO, RT5625_M_RM_L_PHO);
1110 static int rt5625_bt_get(struct snd_kcontrol *kcontrol,
1111 struct snd_ctl_elem_value *ucontrol)
1113 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1114 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1116 ucontrol->value.integer.value[0] =
1117 (rt5625->app_bmp & RT5625_BT_MASK) >> RT5625_BT_BIT;
1122 static int rt5625_bt_put(struct snd_kcontrol *kcontrol,
1123 struct snd_ctl_elem_value *ucontrol)
1125 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1126 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1129 if (!(rt5625->app_bmp & RT5625_REC_MASK)) {
1130 snd_soc_update_bits(codec, RT5625_ADC_REC_MIXER,
1131 RT5625_M_RM_L_MIC1 | RT5625_M_RM_L_MIC2 |
1132 RT5625_M_RM_R_MIC1 | RT5625_M_RM_R_MIC2,
1133 RT5625_M_RM_L_MIC1 | RT5625_M_RM_L_MIC2 |
1134 RT5625_M_RM_R_MIC1 | RT5625_M_RM_R_MIC2);
1137 upd = (rt5625->app_bmp & ~RT5625_BT_MASK) |
1138 (ucontrol->value.integer.value[0] << RT5625_BT_BIT);
1139 if (rt5625->app_bmp != upd) {
1140 rt5625->app_bmp = upd;
1141 rt5625->app_bmp &= ~(RT5625_3G_MASK | RT5625_VOIP_MASK);
1147 static int rt5625_3g_get(struct snd_kcontrol *kcontrol,
1148 struct snd_ctl_elem_value *ucontrol)
1150 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1151 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1153 ucontrol->value.integer.value[0] =
1154 (rt5625->app_bmp & RT5625_3G_MASK) >> RT5625_3G_BIT;
1159 static int rt5625_3g_put(struct snd_kcontrol *kcontrol,
1160 struct snd_ctl_elem_value *ucontrol)
1162 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1163 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1166 rt5625->headset = false;
1167 if (!(rt5625->app_bmp & RT5625_REC_MASK)) {
1168 snd_soc_update_bits(codec, RT5625_ADC_REC_MIXER,
1169 RT5625_M_RM_L_MIC1 | RT5625_M_RM_L_MIC2 | RT5625_M_RM_R_MIC2,
1170 RT5625_M_RM_L_MIC1 | RT5625_M_RM_L_MIC2 | RT5625_M_RM_R_MIC2);
1173 upd = (rt5625->app_bmp & ~RT5625_3G_MASK) |
1174 (ucontrol->value.integer.value[0] << RT5625_3G_BIT);
1175 if (rt5625->app_bmp != upd) {
1176 rt5625->app_bmp = upd;
1177 rt5625->app_bmp &= ~(RT5625_BT_MASK | RT5625_VOIP_MASK);
1183 static int rt5625_hs_3g_put(struct snd_kcontrol *kcontrol,
1184 struct snd_ctl_elem_value *ucontrol)
1186 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1187 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1190 rt5625->headset = true;
1191 if (!(rt5625->app_bmp & RT5625_REC_MASK)) {
1192 snd_soc_update_bits(codec, RT5625_ADC_REC_MIXER,
1193 RT5625_M_RM_L_MIC1 | RT5625_M_RM_L_MIC2 |
1194 RT5625_M_RM_R_MIC1 | RT5625_M_RM_R_MIC2,
1195 RT5625_M_RM_L_MIC1 | RT5625_M_RM_L_MIC2 |
1196 RT5625_M_RM_R_MIC1 | RT5625_M_RM_R_MIC2);
1198 upd = (rt5625->app_bmp & ~RT5625_3G_MASK) |
1199 (ucontrol->value.integer.value[0] << RT5625_3G_BIT);
1200 if (rt5625->app_bmp != upd) {
1201 rt5625->app_bmp = upd;
1202 rt5625->app_bmp &= ~(RT5625_BT_MASK | RT5625_VOIP_MASK);
1208 static int rt5625_dump_dsp_get(struct snd_kcontrol *kcontrol,
1209 struct snd_ctl_elem_value *ucontrol)
1211 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1215 pr_info("\n[ RT5625 DSP Register ]\n");
1216 for (i = 0; i < RT5625_DSP_INIT_NUM; i++) {
1217 val = rt5625_dsp_read(codec, rt5625_dsp_init[i].index);
1218 if (val) pr_info(" 0x%x: 0x%x\n",
1219 rt5625_dsp_init[i].index, val);
1224 static int rt5625_dac_active_get(struct snd_kcontrol *kcontrol,
1225 struct snd_ctl_elem_value *ucontrol)
1227 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1228 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1230 ucontrol->value.integer.value[0] = rt5625->dac_active;
1234 static int rt5625_dac_active_put(struct snd_kcontrol *kcontrol,
1235 struct snd_ctl_elem_value *ucontrol)
1237 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1238 struct snd_soc_dapm_context *dapm = &codec->dapm;
1239 struct snd_soc_dapm_widget *w;
1240 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1242 if(ucontrol->value.integer.value[0] == rt5625->dac_active)
1244 rt5625->dac_active = ucontrol->value.integer.value[0];
1246 /* playback is on-going; do nothing when turn off BT */
1247 if (rt5625->dac_active == 0 && rt5625->app_bmp & RT5625_PLY_MASK)
1250 list_for_each_entry(w, &dapm->card->widgets, list)
1252 if (!w->sname || w->dapm != dapm)
1254 if (strstr(w->sname, "Playback")) {
1255 pr_info("widget %s %s %s\n", w->name, w->sname,
1256 rt5625->dac_active ? "active" : "inactive");
1257 w->active = rt5625->dac_active;
1261 if (!(rt5625->dac_active))
1262 snd_soc_dapm_sync(dapm);
1267 static int rt5625_adc_active_get(struct snd_kcontrol *kcontrol,
1268 struct snd_ctl_elem_value *ucontrol)
1270 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1271 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1273 ucontrol->value.integer.value[0] = rt5625->adc_active;
1277 static int rt5625_adc_active_put(struct snd_kcontrol *kcontrol,
1278 struct snd_ctl_elem_value *ucontrol)
1280 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1281 struct snd_soc_dapm_context *dapm = &codec->dapm;
1282 struct snd_soc_dapm_widget *w;
1283 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1285 if(ucontrol->value.integer.value[0] == rt5625->adc_active)
1287 rt5625->adc_active = ucontrol->value.integer.value[0];
1289 /* record is on-going; do nothing when turn off BT */
1290 if (rt5625->adc_active == 0 && rt5625->app_bmp & RT5625_REC_MASK)
1293 list_for_each_entry(w, &dapm->card->widgets, list)
1295 if (!w->sname || w->dapm != dapm)
1297 if (strstr(w->sname, "Capture")) {
1298 pr_info("widget %s %s %s\n", w->name, w->sname,
1299 rt5625->adc_active ? "active" : "inactive");
1300 w->active = rt5625->adc_active;
1304 if (!(rt5625->adc_active))
1305 snd_soc_dapm_sync(dapm);
1310 static int rt5625_pll_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1312 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1313 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1315 ucontrol->value.integer.value[0] = rt5625->pll_sel;
1320 static int rt5625_pll_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1322 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1323 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1325 if(ucontrol->value.integer.value[0] == rt5625->pll_sel)
1327 rt5625->pll_sel = ucontrol->value.integer.value[0];
1329 switch(rt5625->pll_sel) {
1330 case RT5625_PLL_DIS:
1331 pr_info("%s(): Disable\n", __func__);
1332 snd_soc_update_bits(codec, RT5625_GEN_CTRL1,
1333 RT5625_SCLK_PLL1, 0);
1334 snd_soc_write(codec, RT5625_DAC_CLK_CTRL2, 0);
1337 case RT5625_PLL_112896_225792:
1338 pr_info("%s(): 11.2896>22.5792\n", __func__);
1339 snd_soc_write(codec, RT5625_GEN_CTRL2, 0x0000);
1340 snd_soc_write(codec, RT5625_PLL_CTRL, 0x06a0);
1341 snd_soc_update_bits(codec, RT5625_GEN_CTRL1,
1342 RT5625_SCLK_PLL1, RT5625_SCLK_PLL1);
1343 snd_soc_write(codec, RT5625_DAC_CLK_CTRL2, 0x0210);
1346 case RT5625_PLL_112896_24576:
1347 pr_info("%s(): 11.2896->24.576\n", __func__);
1348 snd_soc_write(codec, RT5625_GEN_CTRL2, 0x0000);
1349 snd_soc_write(codec, RT5625_PLL_CTRL, 0x922f);
1350 snd_soc_update_bits(codec, RT5625_GEN_CTRL1,
1351 RT5625_SCLK_PLL1, RT5625_SCLK_PLL1);
1352 snd_soc_write(codec, RT5625_DAC_CLK_CTRL2, 0x0210);
1362 static int rt5625_pll2_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1364 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1365 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1367 ucontrol->value.integer.value[0] = rt5625->pll2_sel;
1371 static int rt5625_pll2_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1373 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1374 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1376 if(ucontrol->value.integer.value[0] == rt5625->pll2_sel)
1378 rt5625->pll2_sel = ucontrol->value.integer.value[0];
1380 if(rt5625->pll2_sel != RT5625_PLL_DIS) {
1381 snd_soc_update_bits(codec, RT5625_GEN_CTRL1,
1382 RT5625_VSCLK_MASK, RT5625_VSCLK_PLL2);
1383 snd_soc_write(codec, RT5625_PLL2_CTRL, RT5625_PLL2_EN);
1384 snd_soc_write(codec, RT5625_VDAC_CLK_CTRL1,
1385 RT5625_VBCLK_DIV1_4);
1386 snd_soc_update_bits(codec, RT5625_EXT_SDP_CTRL,
1387 RT5625_PCM_CS_MASK, RT5625_PCM_CS_VSCLK);
1393 static const char *rt5625_pll_sel[] = {"Disable", "11.2896->22.5792", "11.2896->24.576"};
1395 static const SOC_ENUM_SINGLE_DECL(rt5625_pll_sel_enum, 0, 0, rt5625_pll_sel);
1397 static const char *rt5625_pll2_sel[] = {"Disable", "Enable"};
1399 static const SOC_ENUM_SINGLE_DECL(rt5625_pll2_sel_enum, 0, 0, rt5625_pll2_sel);
1402 static const char *rt5625_AUXOUT_mode[] = {"Differential mode", "Single-ended mode"};
1403 static const char *rt5625_Differential_Input_Control[] = {"Disable", "Enable"};
1405 static const struct soc_enum rt5625_differential_enum[] = {
1406 SOC_ENUM_SINGLE(RT5625_OUTMIX_CTRL, 4, 2, rt5625_AUXOUT_mode), /*0*/
1407 SOC_ENUM_SINGLE(RT5625_PHONEIN_VOL, 13, 2, rt5625_Differential_Input_Control),/*1*/
1408 SOC_ENUM_SINGLE(RT5625_MIC_VOL, 15, 2, rt5625_Differential_Input_Control), /*2*/
1409 SOC_ENUM_SINGLE(RT5625_MIC_VOL, 7, 2, rt5625_Differential_Input_Control), /*3*/
1412 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0);
1413 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -3525, 75, 0);
1414 static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0);
1415 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1650, 150, 0);
1416 static const DECLARE_TLV_DB_SCALE(dmic_bst_tlv, 0, 600, 0);
1417 /* {0, +20, +30, +40} dB */
1418 static unsigned int mic_bst_tlv[] = {
1419 TLV_DB_RANGE_HEAD(2),
1420 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
1421 1, 3, TLV_DB_SCALE_ITEM(2000, 1000, 0),
1424 #ifdef RT5625_REG_RW
1425 #define REGVAL_MAX 0xffff
1426 static unsigned int regctl_addr = 0x3e;
1427 static int rt5625_regctl_info(struct snd_kcontrol *kcontrol,
1428 struct snd_ctl_elem_info *uinfo)
1430 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1432 uinfo->value.integer.min = 0;
1433 uinfo->value.integer.max = REGVAL_MAX;
1437 static int rt5625_regctl_get(struct snd_kcontrol *kcontrol,
1438 struct snd_ctl_elem_value *ucontrol)
1440 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1441 ucontrol->value.integer.value[0] = regctl_addr;
1442 ucontrol->value.integer.value[1] = snd_soc_read(codec, regctl_addr);
1446 static int rt5625_regctl_put(struct snd_kcontrol *kcontrol,
1447 struct snd_ctl_elem_value *ucontrol)
1449 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1450 regctl_addr = ucontrol->value.integer.value[0];
1451 if(ucontrol->value.integer.value[1] <= REGVAL_MAX)
1452 snd_soc_write(codec, regctl_addr, ucontrol->value.integer.value[1]);
1457 /*speaker ext control*/
1458 static const struct soc_enum spk_ctr_enum =
1459 SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(rt5625_spk_ctr_sel), rt5625_spk_ctr_sel);
1461 static int rt5625_spk_ctr_get(struct snd_kcontrol *kcontrol,
1462 struct snd_ctl_elem_value *ucontrol)
1464 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1465 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1467 ucontrol->value.integer.value[0] = rt5625->spk_ctr_status;
1471 static int rt5625_spk_ctr_put(struct snd_kcontrol *kcontrol,
1472 struct snd_ctl_elem_value *ucontrol)
1474 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1475 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1477 rt5625->spk_ctr_status = ucontrol->value.integer.value[0];
1479 if(rt5625->spk_ctr_pin != INVALID_GPIO)
1481 if(rt5625->spk_ctr_status)
1482 gpio_set_value(rt5625->spk_ctr_pin,rt5625->spk_ctr_on);
1484 gpio_set_value(rt5625->spk_ctr_pin,rt5625->spk_ctr_off);
1489 static const struct snd_kcontrol_new rt5625_snd_controls[] = {
1491 #if defined (CONFIG_SND_SOC_RT5625_SPK_FORM_SPKOUT)
1492 SOC_DOUBLE_TLV("SPKOUT Playback Volume", RT5625_SPK_OUT_VOL,
1493 RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 31, 1, out_vol_tlv),
1494 SOC_DOUBLE("SPKOUT Playback Switch", RT5625_SPK_OUT_VOL,
1495 RT5625_L_MUTE_SFT, RT5625_R_MUTE_SFT, 1, 1),
1496 SOC_DOUBLE_TLV("Earpiece Playback Volume", RT5625_SPK_OUT_VOL,
1497 RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 31, 1, out_vol_tlv),
1498 SOC_DOUBLE("Earpiece Playback Switch", RT5625_SPK_OUT_VOL,
1499 RT5625_L_MUTE_SFT, RT5625_R_MUTE_SFT, 1, 1),
1502 #if defined (CONFIG_SND_SOC_RT5625_SPK_FORM_HPOUT)
1503 SOC_DOUBLE_TLV("SPKOUT Playback Volume", RT5625_HP_OUT_VOL,
1504 RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 31, 1, out_vol_tlv),
1505 SOC_DOUBLE("SPKOUT Playback Switch", RT5625_HP_OUT_VOL,
1506 RT5625_L_MUTE_SFT, RT5625_R_MUTE_SFT, 1, 1),
1507 SOC_DOUBLE_TLV("Earpiece Playback Volume", RT5625_HP_OUT_VOL,
1508 RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 31, 1, out_vol_tlv),
1509 SOC_DOUBLE("Earpiece Playback Switch", RT5625_HP_OUT_VOL,
1510 RT5625_L_MUTE_SFT, RT5625_R_MUTE_SFT, 1, 1),
1511 SOC_ENUM_EXT("SPK_CTR",spk_ctr_enum, rt5625_spk_ctr_get, rt5625_spk_ctr_put),
1514 SOC_ENUM("SPK Amp Type", rt5625_spk_out_enum),
1515 SOC_ENUM("Left SPK Source", rt5625_spkl_src_enum),
1516 SOC_ENUM("SPK Amp Ratio", rt5625_spkamp_ratio_enum),
1517 //SOC_DOUBLE_TLV("Headphone Playback Volume", RT5625_HP_OUT_VOL,
1518 // RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 31, 1, out_vol_tlv),
1519 //SOC_DOUBLE("Headphone Playback Switch", RT5625_HP_OUT_VOL,
1520 // RT5625_L_MUTE_SFT, RT5625_R_MUTE_SFT, 1, 1),
1521 //SOC_ENUM("AUXOUT Mode Control", rt5625_auxout_mode_enum),
1522 SOC_DOUBLE_TLV("AUXOUT Playback Volume", RT5625_AUX_OUT_VOL,
1523 RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 31, 1, out_vol_tlv),
1524 SOC_DOUBLE("AUXOUT Playback Switch", RT5625_AUX_OUT_VOL,
1525 RT5625_L_MUTE_SFT, RT5625_R_MUTE_SFT, 1, 1),
1526 SOC_DOUBLE_TLV("PCM Playback Volume", RT5625_DAC_VOL,
1527 RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 63, 1, dmic_bst_tlv),
1528 //SOC_ENUM("Phone Mode Control", rt5625_phone_mode_enum),
1529 SOC_SINGLE_TLV("Phone Playback Volume", RT5625_PHONEIN_VOL,
1530 RT5625_L_VOL_SFT, 31, 1, in_vol_tlv),
1531 //SOC_ENUM("MIC1 Mode Control", rt5625_mic1_mode_enum),
1532 SOC_SINGLE_TLV("MIC1 Boost", RT5625_MIC_CTRL,
1533 RT5625_MIC1_BST_SFT, 3, 0, mic_bst_tlv),
1534 SOC_SINGLE_TLV("Mic1 Playback Volume", RT5625_MIC_VOL,
1535 RT5625_L_VOL_SFT, 31, 1, in_vol_tlv),
1536 //SOC_ENUM("MIC2 Mode Control", rt5625_mic2_mode_enum),
1537 SOC_SINGLE_TLV("MIC2 Boost", RT5625_MIC_CTRL,
1538 RT5625_MIC2_BST_SFT, 3, 0, mic_bst_tlv),
1539 SOC_SINGLE_TLV("Mic2 Playback Volume", RT5625_MIC_VOL,
1540 RT5625_R_VOL_SFT, 31, 1, in_vol_tlv),
1541 SOC_SINGLE_TLV("Dmic Boost", RT5625_DMIC_CTRL,
1542 RT5625_DIG_BST_SFT, 7, 0, dmic_bst_tlv),
1543 SOC_DOUBLE_TLV("LineIn Playback Volume", RT5625_LINE_IN_VOL,
1544 RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 31, 1, in_vol_tlv),
1545 SOC_DOUBLE_TLV("PCM Capture Volume", RT5625_ADC_REC_GAIN,
1546 RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 31, 0, adc_vol_tlv),
1547 //SOC_DOUBLE_TLV("ADC Record Gain", RT5625_ADC_REC_GAIN,
1548 // RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 31, 0, adc_vol_tlv),
1549 /* This item does'nt affect path connected; only for clock choosen */
1550 SOC_ENUM_EXT("ADCR fun select Control", adcr_fun_sel_enum,
1551 snd_soc_get_enum_double, rt5625_adcr_fun_sel_put),
1552 SOC_ENUM_EXT("ADCL fun select Control", adcl_fun_sel_enum,
1553 snd_soc_get_enum_double, rt5625_adcl_fun_sel_put),
1556 SOC_ENUM_EXT("VoDSP AEC", rt5625_aec_fun_enum,
1557 rt5625_aec_get, rt5625_aec_put),
1558 SOC_ENUM("VoDSP LRCK Control", rt5625_dsp_lrck_enum),
1559 SOC_ENUM("VoDSP BP Pin Control", rt5625_bp_ctrl_enum),
1560 SOC_ENUM("VoDSP Power Down Pin Control", rt5625_pd_ctrl_enum),
1561 SOC_ENUM("VoDSP Reset Pin Control", rt5625_rst_ctrl_enum),
1563 #ifdef RT5625_F_SMT_PHO
1564 SOC_ENUM("GPIO2 mode", rt5625_gpio2_enum[0]),
1565 SOC_ENUM("GPIO2 configuration", rt5625_gpio2_enum[1]),
1566 SOC_ENUM("GPIO2 level", rt5625_gpio2_enum[2]),
1568 SOC_SINGLE_EXT("VoDSP Dump", 0, 0, 1, 0, rt5625_dump_dsp_get, NULL),
1569 SOC_SINGLE_EXT("DAC Switch", 0, 0, 1, 0, rt5625_dac_active_get, rt5625_dac_active_put),
1570 SOC_SINGLE_EXT("ADC Switch", 0, 0, 1, 0, rt5625_adc_active_get, rt5625_adc_active_put),
1571 SOC_ENUM_EXT("PLL Switch", rt5625_pll_sel_enum, rt5625_pll_get, rt5625_pll_put),
1572 SOC_ENUM_EXT("PLL2 Switch", rt5625_pll2_sel_enum, rt5625_pll2_get, rt5625_pll2_put),
1573 SOC_SINGLE_EXT("VoIP Check", 0, 0, 1, 0, rt5625_voip_get, rt5625_voip_chk_put),
1574 SOC_SINGLE_EXT("VoIP Switch", 0, 0, 1, 0, rt5625_voip_get, rt5625_voip_put),
1575 SOC_SINGLE_EXT("Capture VoIP Check", 0, 0, 1, 0, rt5625_voip_get, rt5625_cap_voip_chk_put),
1576 SOC_SINGLE_EXT("Capture VoIP Switch", 0, 0, 1, 0, rt5625_voip_get, rt5625_cap_voip_put),
1577 SOC_SINGLE_EXT("Headset VoIP Check", 0, 0, 1, 0, rt5625_voip_get, rt5625_hs_voip_chk_put),
1578 SOC_SINGLE_EXT("Headset VoIP Switch", 0, 0, 1, 0, rt5625_voip_get, rt5625_hs_voip_put),
1579 SOC_SINGLE_EXT("Playback Switch", 0, 0, 1, 0, rt5625_play_get, rt5625_play_put),
1580 SOC_SINGLE_EXT("Record Switch", 0, 0, 1, 0, rt5625_rec_get, rt5625_rec_put),
1581 SOC_SINGLE_EXT("BT Switch", 0, 0, 1, 0, rt5625_bt_get, rt5625_bt_put),
1582 SOC_SINGLE_EXT("3G Switch", 0, 0, 1, 0, rt5625_3g_get, rt5625_3g_put),
1583 SOC_SINGLE_EXT("Headset 3G Switch", 0, 0, 1, 0, rt5625_3g_get, rt5625_hs_3g_put),
1584 SOC_SINGLE_EXT("APP disp", 0, 0, 1, 0, rt5625_app_get, NULL),
1586 //SOC_DOUBLE_TLV("SPKOUT Playback Volume", RT5625_SPK_OUT_VOL,
1587 // RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 31, 1, out_vol_tlv),
1588 //SOC_DOUBLE("SPKOUT Playback Switch", RT5625_SPK_OUT_VOL,
1589 // RT5625_L_MUTE_SFT, RT5625_R_MUTE_SFT, 1, 1),
1590 SOC_DOUBLE_TLV("HPOUT Playback Volume", RT5625_HP_OUT_VOL,
1591 RT5625_L_VOL_SFT, RT5625_R_VOL_SFT, 31, 1, out_vol_tlv),
1592 SOC_DOUBLE("HPOUT Playback Switch", RT5625_HP_OUT_VOL,
1593 RT5625_L_MUTE_SFT, RT5625_R_MUTE_SFT, 1, 1),
1594 SOC_ENUM("AUXOUT mode switch", rt5625_differential_enum[0]),
1595 SOC_ENUM("Phone Differential Input Control", rt5625_differential_enum[1]),
1596 SOC_ENUM("MIC1 Differential Input Control", rt5625_differential_enum[2]),
1597 SOC_ENUM("MIC2 Differential Input Control", rt5625_differential_enum[3]),
1599 #ifdef RT5625_REG_RW
1601 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1602 .name = "Register Control",
1603 .info = rt5625_regctl_info,
1604 .get = rt5625_regctl_get,
1605 .put = rt5625_regctl_put,
1611 /*Left ADC Rec mixer*/
1612 static const struct snd_kcontrol_new rt5625_adcl_rec_mixer[] = {
1613 SOC_DAPM_SINGLE("Mic1 Capture Switch", RT5625_ADC_REC_MIXER,
1614 RT5625_M_RM_L_MIC1_SFT, 1, 1),
1615 SOC_DAPM_SINGLE("Mic2 Capture Switch", RT5625_ADC_REC_MIXER,
1616 RT5625_M_RM_L_MIC2_SFT, 1, 1),
1617 SOC_DAPM_SINGLE("LineIn Capture Switch", RT5625_ADC_REC_MIXER,
1618 RT5625_M_RM_L_LINE_SFT, 1, 1),
1619 SOC_DAPM_SINGLE("Phone Capture Switch", RT5625_ADC_REC_MIXER,
1620 RT5625_M_RM_L_PHO_SFT, 1, 1),
1621 SOC_DAPM_SINGLE("HP Mixer Capture Switch", RT5625_ADC_REC_MIXER,
1622 RT5625_M_RM_L_HM_SFT, 1, 1),
1623 SOC_DAPM_SINGLE("SPK Mixer Capture Switch", RT5625_ADC_REC_MIXER,
1624 RT5625_M_RM_L_SM_SFT, 1, 1),
1625 SOC_DAPM_SINGLE("MoNo Mixer Capture Switch", RT5625_ADC_REC_MIXER,
1626 RT5625_M_RM_L_MM_SFT, 1, 1),
1629 /*Right ADC Rec mixer*/
1630 static const struct snd_kcontrol_new rt5625_adcr_rec_mixer[] = {
1631 SOC_DAPM_SINGLE("Mic1 Capture Switch", RT5625_ADC_REC_MIXER,
1632 RT5625_M_RM_R_MIC1_SFT, 1, 1),
1633 SOC_DAPM_SINGLE("Mic2 Capture Switch", RT5625_ADC_REC_MIXER,
1634 RT5625_M_RM_R_MIC2_SFT, 1, 1),
1635 SOC_DAPM_SINGLE("LineIn Capture Switch", RT5625_ADC_REC_MIXER,
1636 RT5625_M_RM_R_LINE_SFT, 1, 1),
1637 SOC_DAPM_SINGLE("Phone Capture Switch", RT5625_ADC_REC_MIXER,
1638 RT5625_M_RM_R_PHO_SFT, 1, 1),
1639 SOC_DAPM_SINGLE("HP Mixer Capture Switch", RT5625_ADC_REC_MIXER,
1640 RT5625_M_RM_R_HM_SFT, 1, 1),
1641 SOC_DAPM_SINGLE("SPK Mixer Capture Switch", RT5625_ADC_REC_MIXER,
1642 RT5625_M_RM_R_SM_SFT, 1, 1),
1643 SOC_DAPM_SINGLE("MoNo Mixer Capture Switch", RT5625_ADC_REC_MIXER,
1644 RT5625_M_RM_R_MM_SFT, 1, 1),
1647 /* HP Mixer for mono input */
1648 static const struct snd_kcontrol_new rt5625_hp_mixer[] = {
1649 SOC_DAPM_SINGLE("LineIn Playback Switch", RT5625_LINE_IN_VOL,
1650 RT5625_M_LI_HM_SFT, 1, 1),
1651 SOC_DAPM_SINGLE("Phone Playback Switch", RT5625_PHONEIN_VOL,
1652 RT5625_M_PHO_HM_SFT, 1, 1),
1653 SOC_DAPM_SINGLE("Mic1 Playback Switch", RT5625_DAC_MIC_CTRL,
1654 RT5625_M_MIC1_HM_SFT, 1, 1),
1655 SOC_DAPM_SINGLE("Mic2 Playback Switch", RT5625_DAC_MIC_CTRL,
1656 RT5625_M_MIC2_HM_SFT, 1, 1),
1657 SOC_DAPM_SINGLE("Voice DAC Playback Switch", RT5625_VDAC_OUT_VOL,
1658 RT5625_M_VDAC_HM_SFT, 1, 1),
1662 static const struct snd_kcontrol_new rt5625_hpl_mixer[] = {
1663 SOC_DAPM_SINGLE("ADC Playback Switch", RT5625_ADC_REC_GAIN,
1664 RT5625_M_ADCL_HM_SFT, 1, 1),
1665 SOC_DAPM_SINGLE("DAC Playback Switch", RT5625_DAC_MIC_CTRL,
1666 RT5625_M_DACL_HM_SFT, 1, 1),
1669 /* Right HP Mixer */
1670 static const struct snd_kcontrol_new rt5625_hpr_mixer[] = {
1671 SOC_DAPM_SINGLE("ADC Playback Switch", RT5625_ADC_REC_GAIN,
1672 RT5625_M_ADCR_HM_SFT, 1, 1),
1673 SOC_DAPM_SINGLE("DAC Playback Switch", RT5625_DAC_MIC_CTRL,
1674 RT5625_M_DACR_HM_SFT, 1, 1),
1678 static const struct snd_kcontrol_new rt5625_mono_mixer[] = {
1679 SOC_DAPM_SINGLE("ADCL Playback Switch", RT5625_ADC_REC_GAIN,
1680 RT5625_M_ADCL_MM_SFT, 1, 1),
1681 SOC_DAPM_SINGLE("ADCR Playback Switch", RT5625_ADC_REC_GAIN,
1682 RT5625_M_ADCR_MM_SFT, 1, 1),
1683 SOC_DAPM_SINGLE("Line Mixer Playback Switch", RT5625_LINE_IN_VOL,
1684 RT5625_M_LI_MM_SFT, 1, 1),
1685 SOC_DAPM_SINGLE("Mic1 Playback Switch", RT5625_DAC_MIC_CTRL,
1686 RT5625_M_MIC1_MM_SFT, 1, 1),
1687 SOC_DAPM_SINGLE("Mic2 Playback Switch", RT5625_DAC_MIC_CTRL,
1688 RT5625_M_MIC2_MM_SFT, 1, 1),
1689 SOC_DAPM_SINGLE("DAC Mixer Playback Switch", RT5625_DAC_MIC_CTRL,
1690 RT5625_M_DAC_MM_SFT, 1, 1),
1691 SOC_DAPM_SINGLE("Voice DAC Playback Switch", RT5625_VDAC_OUT_VOL,
1692 RT5625_M_VDAC_MM_SFT, 1, 1),
1696 static const struct snd_kcontrol_new rt5625_spk_mixer[] = {
1697 SOC_DAPM_SINGLE("Line Mixer Playback Switch", RT5625_LINE_IN_VOL,
1698 RT5625_M_LI_SM_SFT, 1, 1),
1699 SOC_DAPM_SINGLE("Phone Playback Switch", RT5625_PHONEIN_VOL,
1700 RT5625_M_PHO_SM_SFT, 1, 1),
1701 SOC_DAPM_SINGLE("Mic1 Playback Switch", RT5625_DAC_MIC_CTRL,
1702 RT5625_M_MIC1_SM_SFT, 1, 1),
1703 SOC_DAPM_SINGLE("Mic2 Playback Switch", RT5625_DAC_MIC_CTRL,
1704 RT5625_M_MIC2_SM_SFT, 1, 1),
1705 SOC_DAPM_SINGLE("DAC Mixer Playback Switch", RT5625_DAC_MIC_CTRL,
1706 RT5625_M_DAC_SM_SFT, 1, 1),
1707 SOC_DAPM_SINGLE("Voice DAC Playback Switch", RT5625_VDAC_OUT_VOL,
1708 RT5625_M_VDAC_SM_SFT, 1, 1),
1711 static int rt5625_dac_func_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *k, int event)
1713 struct snd_soc_codec *codec = w->codec;
1716 case SND_SOC_DAPM_PRE_REG:
1717 snd_soc_update_bits(codec, RT5625_PD_CTRL,
1718 RT5625_PWR_PR1, RT5625_PWR_PR1);
1721 case SND_SOC_DAPM_POST_REG:
1722 snd_soc_update_bits(codec, RT5625_PD_CTRL,
1733 static int rt5625_hpmix_event(struct snd_soc_dapm_widget *w,
1734 struct snd_kcontrol *kcontrol, int event)
1736 struct snd_soc_codec *codec = w->codec;
1739 case SND_SOC_DAPM_PRE_PMD:
1740 snd_soc_update_bits(codec, RT5625_PWR_ADD2,
1741 RT5625_P_HM_L | RT5625_P_HM_R, 0);
1744 case SND_SOC_DAPM_POST_PMU:
1745 snd_soc_update_bits(codec, RT5625_PWR_ADD2,
1746 RT5625_P_HM_L | RT5625_P_HM_R,
1747 RT5625_P_HM_L | RT5625_P_HM_R);
1757 static int rt5625_vodsp_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *k, int event)
1759 struct snd_soc_codec *codec = w->codec;
1760 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
1763 case SND_SOC_DAPM_POST_PMD:
1764 //pr_info("%s(): PMD\n", __func__);
1765 snd_soc_update_bits(codec, RT5625_VODSP_CTL,
1766 RT5625_DSP_PD_MASK, RT5625_DSP_PD_EN);
1767 snd_soc_update_bits(codec, RT5625_PWR_ADD3,
1768 RT5625_P_DSP_IF | RT5625_P_DSP_I2C, 0);
1769 snd_soc_update_bits(codec, RT5625_LDO_CTRL,
1770 RT5625_LDO_MASK, RT5625_LDO_DIS);
1773 case SND_SOC_DAPM_POST_PMU:
1774 //pr_info("%s(): PMU\n", __func__);
1775 if(rt5625->vodsp_fun == RT5625_AEC_EN)
1776 rt5625_init_vodsp_aec(codec);
1777 //pr_info("[DSP poweron] 0x%04x: 0x%04x\n", 0x230C, rt5625_dsp_read(codec, 0x230C));
1788 static void hp_depop_mode2(struct snd_soc_codec *codec)
1790 snd_soc_update_bits(codec, RT5625_PWR_ADD1,
1791 RT5625_P_SG_EN, RT5625_P_SG_EN);
1792 snd_soc_update_bits(codec, RT5625_PWR_ADD3,
1793 RT5625_P_HPL_VOL | RT5625_P_HPR_VOL,
1794 RT5625_P_HPL_VOL | RT5625_P_HPR_VOL);
1795 snd_soc_write(codec, RT5625_MISC_CTRL, RT5625_HP_DEPOP_M2);
1796 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
1797 snd_soc_update_bits(codec, RT5625_PWR_ADD1,
1798 RT5625_P_HPO_AMP | RT5625_P_HPO_ENH,
1799 RT5625_P_HPO_AMP | RT5625_P_HPO_ENH);
1802 /* enable depop function for mute/unmute */
1803 static void hp_mute_unmute_depop(struct snd_soc_codec *codec,int mute)
1806 snd_soc_update_bits(codec, RT5625_PWR_ADD1,
1807 RT5625_P_SG_EN, RT5625_P_SG_EN);
1808 snd_soc_write(codec, RT5625_MISC_CTRL, RT5625_MUM_DEPOP |
1809 RT5625_HPR_MUM_DEPOP | RT5625_HPL_MUM_DEPOP);
1810 snd_soc_update_bits(codec, RT5625_HP_OUT_VOL,
1811 RT5625_L_MUTE | RT5625_R_MUTE,
1812 RT5625_L_MUTE | RT5625_R_MUTE);
1814 snd_soc_update_bits(codec, RT5625_PWR_ADD1, RT5625_P_SG_EN, 0);
1816 snd_soc_update_bits(codec, RT5625_PWR_ADD1,
1817 RT5625_P_SG_EN, RT5625_P_SG_EN);
1818 snd_soc_write(codec, RT5625_MISC_CTRL, RT5625_MUM_DEPOP |
1819 RT5625_HPR_MUM_DEPOP | RT5625_HPL_MUM_DEPOP);
1820 snd_soc_update_bits(codec,RT5625_HP_OUT_VOL,
1821 RT5625_L_MUTE | RT5625_R_MUTE, 0);
1826 static int rt5625_hp_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *k, int event)
1828 struct snd_soc_codec *codec = w->codec;
1831 case SND_SOC_DAPM_PRE_PMD:
1832 hp_mute_unmute_depop(codec,1);
1833 snd_soc_update_bits(codec, RT5625_PWR_ADD1,
1834 RT5625_P_HPO_AMP | RT5625_P_HPO_ENH, 0);
1835 snd_soc_update_bits(codec, RT5625_PWR_ADD3,
1836 RT5625_P_HPL_VOL | RT5625_P_HPR_VOL, 0);
1839 case SND_SOC_DAPM_POST_PMU:
1840 hp_depop_mode2(codec);
1841 hp_mute_unmute_depop(codec,0);
1851 /* DAC function select MUX */
1852 static const char *dac_fun_sel[] = {
1853 "Stereo DAC", "SRC2 Out", "TxDP", "TxDC"};
1855 static const struct soc_enum dac_fun_sel_enum =
1856 SOC_ENUM_SINGLE(RT5625_F_DAC_ADC_VDAC, RT5625_DAC_F_SFT,
1857 ARRAY_SIZE(dac_fun_sel), dac_fun_sel);
1859 static const struct snd_kcontrol_new dac_fun_sel_mux =
1860 SOC_DAPM_ENUM("DAC Function Select Mux", dac_fun_sel_enum);
1862 /* Voice DAC source select MUX */
1863 static const char *vdac_src_sel[] = {
1864 "Voice PCM", "SRC2 Out", "TxDP", "TxDC"};
1866 static const struct soc_enum vdac_src_sel_enum =
1867 SOC_ENUM_SINGLE(RT5625_F_DAC_ADC_VDAC, RT5625_VDAC_S_SFT,
1868 ARRAY_SIZE(vdac_src_sel), vdac_src_sel);
1870 static const struct snd_kcontrol_new vdac_src_sel_mux =
1871 SOC_DAPM_ENUM("Voice DAC Source Mux", vdac_src_sel_enum);
1873 /* SRC1 power switch */
1874 static const struct snd_kcontrol_new src1_pwr_sw_control =
1875 SOC_DAPM_SINGLE("Switch", RT5625_VODSP_PDM_CTL,
1876 RT5625_SRC1_PWR_SFT, 1, 0);
1878 /* SRC2 power switch */
1879 static const struct snd_kcontrol_new src2_pwr_sw_control =
1880 SOC_DAPM_SINGLE("Switch", RT5625_VODSP_PDM_CTL,
1881 RT5625_SRC2_PWR_SFT, 1, 0);
1883 /* SRC2 source select MUX */
1884 static const char *src2_src_sel[] = {"TxDP", "TxDC"};
1886 static const struct soc_enum src2_src_sel_enum =
1887 SOC_ENUM_SINGLE(RT5625_VODSP_PDM_CTL, RT5625_SRC2_S_SFT,
1888 ARRAY_SIZE(src2_src_sel), src2_src_sel);
1890 static const struct snd_kcontrol_new src2_src_sel_mux =
1891 SOC_DAPM_ENUM("SRC2 Source Mux", src2_src_sel_enum);
1893 /* VoDSP RxDP power switch */
1894 static const struct snd_kcontrol_new rxdp_pwr_sw_control =
1895 SOC_DAPM_SINGLE("Switch", RT5625_VODSP_PDM_CTL,
1896 RT5625_RXDP_PWR_SFT, 1, 0);
1897 /* VoDSP RxDC power switch */
1898 static const struct snd_kcontrol_new rxdc_pwr_sw_control =
1899 SOC_DAPM_SINGLE("Switch", RT5625_VODSP_PDM_CTL,
1900 RT5625_RXDC_PWR_SFT, 1, 0);
1902 /* VoDSP RxDP source select MUX */
1903 static const char *rxdp_src_sel[] = {"SRC1 Output", "ADCL to VoDSP",
1904 "Voice to Stereo", "ADCR to VoDSP"};
1906 static const struct soc_enum rxdp_src_sel_enum =
1907 SOC_ENUM_SINGLE(RT5625_VODSP_PDM_CTL, RT5625_RXDP_S_SFT,
1908 ARRAY_SIZE(rxdp_src_sel), rxdp_src_sel);
1910 static const struct snd_kcontrol_new rxdp_src_sel_mux =
1911 SOC_DAPM_ENUM("RxDP Source Mux", rxdp_src_sel_enum);
1913 /* PCM source select MUX */
1914 static const char *pcm_src_sel[] = {"ADCR", "TxDP"};
1916 static const struct soc_enum pcm_src_sel_enum =
1917 SOC_ENUM_SINGLE(RT5625_VODSP_PDM_CTL, RT5625_PCM_S_SFT,
1918 ARRAY_SIZE(pcm_src_sel), pcm_src_sel);
1920 static const struct snd_kcontrol_new pcm_src_sel_mux =
1921 SOC_DAPM_ENUM("PCM Source Mux", pcm_src_sel_enum);
1923 /* Main stereo record I2S source select MUX */
1924 static const char *rec_iis_src_sel[] = {"ADC", "Voice to Stereo", "SRC2 Output"};
1926 static const struct soc_enum rec_iis_src_enum =
1927 SOC_ENUM_SINGLE(RT5625_VODSP_PDM_CTL, RT5625_REC_IIS_S_SFT,
1928 ARRAY_SIZE(rec_iis_src_sel), rec_iis_src_sel);
1930 static const struct snd_kcontrol_new rec_iis_src_mux =
1931 SOC_DAPM_ENUM("REC I2S Source Mux", rec_iis_src_enum);
1933 /* SPK volume input select MUX */
1934 static const char *spkvol_input_sel[] = {"VMID", "HP Mixer", "SPK Mixer", "Mono Mixer"};
1936 static const struct soc_enum spkvol_input_enum =
1937 SOC_ENUM_SINGLE(RT5625_OUTMIX_CTRL, RT5625_SPKVOL_S_SFT,
1938 ARRAY_SIZE(spkvol_input_sel), spkvol_input_sel);
1940 static const struct snd_kcontrol_new spkvol_input_mux =
1941 SOC_DAPM_ENUM("SPK Vol Input Mux", spkvol_input_enum);
1943 /* HP volume input select MUX */
1944 static const char *hpvol_input_sel[] = {"VMID", "HP Mixer"};
1946 static const struct soc_enum hplvol_input_enum =
1947 SOC_ENUM_SINGLE(RT5625_OUTMIX_CTRL, RT5625_HPVOL_L_S_SFT,
1948 ARRAY_SIZE(hpvol_input_sel), hpvol_input_sel);
1950 static const struct snd_kcontrol_new hplvol_input_mux =
1951 SOC_DAPM_ENUM("HPL Vol Input Mux", hplvol_input_enum);
1953 static const struct soc_enum hprvol_input_enum =
1954 SOC_ENUM_SINGLE(RT5625_OUTMIX_CTRL, RT5625_HPVOL_R_S_SFT,
1955 ARRAY_SIZE(hpvol_input_sel), hpvol_input_sel);
1957 static const struct snd_kcontrol_new hprvol_input_mux =
1958 SOC_DAPM_ENUM("HPR Vol Input Mux", hprvol_input_enum);
1960 /* AUX volume input select MUX */
1961 static const struct soc_enum auxvol_input_enum =
1962 SOC_ENUM_SINGLE(RT5625_OUTMIX_CTRL, RT5625_AUXVOL_S_SFT,
1963 ARRAY_SIZE(spkvol_input_sel), spkvol_input_sel);
1965 static const struct snd_kcontrol_new auxvol_input_mux =
1966 SOC_DAPM_ENUM("AUX Vol Input Mux", auxvol_input_enum);
1968 static const struct snd_soc_dapm_widget rt5625_dapm_widgets[] = {
1970 SND_SOC_DAPM_SUPPLY("IIS Interface", RT5625_PWR_ADD1,
1971 RT5625_P_I2S_BIT, 0, NULL, 0),
1972 SND_SOC_DAPM_SUPPLY("PLL1", RT5625_PWR_ADD2,
1973 RT5625_P_PLL1_BIT, 0, NULL, 0),
1974 SND_SOC_DAPM_SUPPLY("PLL2", RT5625_PWR_ADD2,
1975 RT5625_P_PLL2_BIT, 0, NULL, 0),
1976 SND_SOC_DAPM_VMID("VMID"),
1977 SND_SOC_DAPM_SUPPLY("DAC Ref", RT5625_PWR_ADD1,
1978 RT5625_P_DAC_REF_BIT, 0, NULL, 0),
1979 /* microphone bias */
1980 SND_SOC_DAPM_MICBIAS("Mic1 Bias", RT5625_PWR_ADD1,
1981 RT5625_P_MB1_BIT, 0),
1982 SND_SOC_DAPM_MICBIAS("Mic2 Bias", RT5625_PWR_ADD1,
1983 RT5625_P_MB2_BIT, 0),
1986 SND_SOC_DAPM_INPUT("Left LineIn"),
1987 SND_SOC_DAPM_INPUT("Right LineIn"),
1988 SND_SOC_DAPM_INPUT("Phone"),
1989 SND_SOC_DAPM_INPUT("Mic1"),
1990 SND_SOC_DAPM_INPUT("Mic2"),
1992 SND_SOC_DAPM_PGA("Mic1 Boost", RT5625_PWR_ADD3,
1993 RT5625_P_MIC1_BST_BIT, 0, NULL, 0),
1994 SND_SOC_DAPM_PGA("Mic2 Boost", RT5625_PWR_ADD3,
1995 RT5625_P_MIC2_BST_BIT, 0, NULL, 0),
1996 SND_SOC_DAPM_PGA("Phone Rec Mixer", RT5625_PWR_ADD3,
1997 RT5625_P_PH_ADMIX_BIT, 0, NULL, 0),
1999 SND_SOC_DAPM_MIXER("Left Rec Mixer", RT5625_PWR_ADD2,
2000 RT5625_P_ADCL_RM_BIT, 0, rt5625_adcl_rec_mixer,
2001 ARRAY_SIZE(rt5625_adcl_rec_mixer)),
2002 SND_SOC_DAPM_MIXER("Right Rec Mixer", RT5625_PWR_ADD2,
2003 RT5625_P_ADCR_RM_BIT, 0, rt5625_adcr_rec_mixer,
2004 ARRAY_SIZE(rt5625_adcr_rec_mixer)),
2006 SND_SOC_DAPM_ADC("Left ADC", NULL, RT5625_PWR_ADD2,
2007 RT5625_P_ADCL_BIT, 0),
2008 SND_SOC_DAPM_ADC("Right ADC", NULL, RT5625_PWR_ADD2,
2009 RT5625_P_ADCR_BIT, 0),
2010 SND_SOC_DAPM_PGA("ADC", SND_SOC_NOPM, 0, 0, NULL, 0),//johnny-3-9
2011 SND_SOC_DAPM_MUX("PCM src select Mux", SND_SOC_NOPM, 0, 0,
2013 SND_SOC_DAPM_MUX("IIS src select Mux", SND_SOC_NOPM, 0, 0,
2016 /* Input Stream Audio Interface */
2017 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 HiFi Capture", 0, SND_SOC_NOPM, 0, 0),
2018 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Voice Capture", 0, SND_SOC_NOPM, 0, 0),
2021 SND_SOC_DAPM_MUX("SRC2 src select Mux", SND_SOC_NOPM, 0, 0,
2023 SND_SOC_DAPM_SWITCH("SRC1 Enable", SND_SOC_NOPM, 0, 0,
2024 &src1_pwr_sw_control),
2025 SND_SOC_DAPM_SWITCH("SRC2 Enable", SND_SOC_NOPM, 0, 0,
2026 &src2_pwr_sw_control),
2027 SND_SOC_DAPM_SWITCH("RxDP Enable", SND_SOC_NOPM, 0, 0,
2028 &rxdp_pwr_sw_control),
2029 SND_SOC_DAPM_SWITCH("RxDC Enable", SND_SOC_NOPM, 0, 0,
2030 &rxdc_pwr_sw_control),
2032 SND_SOC_DAPM_MUX("RxDP src select Mux", SND_SOC_NOPM, 0, 0,
2035 SND_SOC_DAPM_PGA("TxDP", SND_SOC_NOPM, 0, 0, NULL, 0),
2036 SND_SOC_DAPM_PGA("TxDC", SND_SOC_NOPM, 0, 0, NULL, 0),
2037 SND_SOC_DAPM_PGA("PDM", SND_SOC_NOPM, 0, 0, NULL, 0),
2038 SND_SOC_DAPM_PGA("RxDP", SND_SOC_NOPM, 0, 0, NULL, 0),
2039 SND_SOC_DAPM_PGA("RxDC", SND_SOC_NOPM, 0, 0, NULL, 0),
2040 SND_SOC_DAPM_PGA_E("Voice DSP", SND_SOC_NOPM,
2041 0, 0, NULL, 0, rt5625_vodsp_event,
2042 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
2045 /* Output Stream Audio Interface */
2046 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 HiFi Playback",
2047 0, SND_SOC_NOPM, 0, 0),
2048 SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Voice Playback",
2049 0, SND_SOC_NOPM, 0, 0),
2051 /* DAC function select Mux */
2052 SND_SOC_DAPM_MUX_E("DAC fun Mux", SND_SOC_NOPM, 0, 0,
2053 &dac_fun_sel_mux, rt5625_dac_func_event,
2054 SND_SOC_DAPM_PRE_REG | SND_SOC_DAPM_POST_REG),
2055 /* VDAC source select Mux */
2056 SND_SOC_DAPM_MUX_E("VDAC src Mux", SND_SOC_NOPM, 0, 0,
2057 &vdac_src_sel_mux, rt5625_dac_func_event,
2058 SND_SOC_DAPM_PRE_REG | SND_SOC_DAPM_POST_REG),
2060 SND_SOC_DAPM_DAC("Left DAC", NULL, RT5625_PWR_ADD2,
2061 RT5625_P_DACL_BIT, 0),
2062 SND_SOC_DAPM_DAC("Right DAC", NULL, RT5625_PWR_ADD2,
2063 RT5625_P_DACR_BIT, 0),
2064 SND_SOC_DAPM_DAC("Voice DAC", NULL, RT5625_PWR_ADD2,
2065 RT5625_P_VDAC_BIT, 0),
2067 SND_SOC_DAPM_PGA("Mic1 Volume", RT5625_PWR_ADD3,
2068 RT5625_P_MIC1_VOL_BIT, 0, NULL, 0),
2069 SND_SOC_DAPM_PGA("Mic2 Volume", RT5625_PWR_ADD3,
2070 RT5625_P_MIC2_VOL_BIT, 0, NULL, 0),
2071 SND_SOC_DAPM_PGA("Left LineIn Volume", RT5625_PWR_ADD3,
2072 RT5625_P_LV_L_BIT, 0, NULL, 0),
2073 SND_SOC_DAPM_PGA("Right LineIn Volume", RT5625_PWR_ADD3,
2074 RT5625_P_LV_R_BIT, 0, NULL, 0),
2075 SND_SOC_DAPM_PGA("Phone Volume", RT5625_PWR_ADD3,
2076 RT5625_P_PH_VOL_BIT, 0, NULL, 0),
2078 SND_SOC_DAPM_PGA("Left DAC To Mixer", RT5625_PWR_ADD1,
2079 RT5625_P_DACL_MIX_BIT, 0, NULL, 0),
2080 SND_SOC_DAPM_PGA("Right DAC To Mixer", RT5625_PWR_ADD1,
2081 RT5625_P_DACR_MIX_BIT, 0, NULL, 0),
2082 SND_SOC_DAPM_PGA("Voice DAC To Mixer", RT5625_PWR_ADD1,
2083 RT5625_P_VDAC_MIX_BIT, 0, NULL, 0),
2085 SND_SOC_DAPM_MIXER("SPK Mixer", RT5625_PWR_ADD2,
2086 RT5625_P_SM_BIT, 0, rt5625_spk_mixer,
2087 ARRAY_SIZE(rt5625_spk_mixer)),
2088 SND_SOC_DAPM_MIXER("Mono HP Mixer", SND_SOC_NOPM, 0, 0,
2089 rt5625_hp_mixer, ARRAY_SIZE(rt5625_hp_mixer)),
2090 SND_SOC_DAPM_MIXER("Left HP Mixer", SND_SOC_NOPM, 0, 0,
2091 rt5625_hpl_mixer, ARRAY_SIZE(rt5625_hpl_mixer)),
2092 SND_SOC_DAPM_MIXER("Right HP Mixer", SND_SOC_NOPM, 0, 0,
2093 rt5625_hpr_mixer, ARRAY_SIZE(rt5625_hpr_mixer)),
2094 SND_SOC_DAPM_MIXER("Mono Mixer", RT5625_PWR_ADD2,
2095 RT5625_P_MM_BIT, 0, rt5625_mono_mixer,
2096 ARRAY_SIZE(rt5625_mono_mixer)),
2098 SND_SOC_DAPM_MIXER_E("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0,
2099 rt5625_hpmix_event, SND_SOC_DAPM_PRE_PMD |
2100 SND_SOC_DAPM_POST_PMU),
2102 SND_SOC_DAPM_MIXER("DAC Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
2103 SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
2105 SND_SOC_DAPM_MUX("SPK Vol Input Mux", SND_SOC_NOPM,
2106 0, 0, &spkvol_input_mux),
2107 SND_SOC_DAPM_SUPPLY("SPKL Vol", RT5625_PWR_ADD3,
2108 RT5625_P_SPKL_VOL_BIT, 0, NULL, 0),
2109 SND_SOC_DAPM_SUPPLY("SPKR Vol", RT5625_PWR_ADD3,
2110 RT5625_P_SPKR_VOL_BIT, 0, NULL, 0),
2111 SND_SOC_DAPM_MUX("HPL Vol Input Mux", RT5625_PWR_ADD3,
2112 RT5625_P_HPL_VOL_BIT, 0, &hplvol_input_mux),
2113 SND_SOC_DAPM_MUX("HPR Vol Input Mux", RT5625_PWR_ADD3,
2114 RT5625_P_HPR_VOL_BIT, 0, &hprvol_input_mux),
2115 SND_SOC_DAPM_MUX("AUX Vol Input Mux", RT5625_PWR_ADD3,
2116 RT5625_P_AUX_VOL_BIT, 0, &auxvol_input_mux),
2118 SND_SOC_DAPM_SUPPLY("SPK Amp", RT5625_PWR_ADD1,
2119 RT5625_P_SPK_AMP_BIT, 0, NULL, 0),
2120 SND_SOC_DAPM_PGA_E("HP Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
2121 rt5625_hp_event, SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
2123 SND_SOC_DAPM_OUTPUT("SPKL"),
2124 SND_SOC_DAPM_OUTPUT("SPKR"),
2125 SND_SOC_DAPM_OUTPUT("HPL"),
2126 SND_SOC_DAPM_OUTPUT("HPR"),
2127 SND_SOC_DAPM_OUTPUT("AUX"),
2130 static const struct snd_soc_dapm_route rt5625_dapm_routes[] = {
2131 {"DAC Ref", NULL, "IIS Interface"},
2132 {"DAC Ref", NULL, "PLL1"},
2133 {"DAC Ref", NULL, "PLL2"},
2136 {"Phone Rec Mixer", NULL, "Phone"},
2137 {"Mic1 Boost", NULL, "Mic1"},
2138 {"Mic2 Boost", NULL, "Mic2"},
2140 {"Left Rec Mixer", "LineIn Capture Switch", "Left LineIn"},
2141 {"Left Rec Mixer", "Phone Capture Switch", "Phone Rec Mixer"},
2142 {"Left Rec Mixer", "Mic1 Capture Switch", "Mic1 Boost"},
2143 {"Left Rec Mixer", "Mic2 Capture Switch", "Mic2 Boost"},
2144 {"Left Rec Mixer", "HP Mixer Capture Switch", "Left HP Mixer"},
2145 {"Left Rec Mixer", "SPK Mixer Capture Switch", "SPK Mixer"},
2146 {"Left Rec Mixer", "MoNo Mixer Capture Switch", "Mono Mixer"},
2148 {"Right Rec Mixer", "LineIn Capture Switch", "Right LineIn"},
2149 {"Right Rec Mixer", "Phone Capture Switch", "Phone Rec Mixer"},
2150 {"Right Rec Mixer", "Mic1 Capture Switch", "Mic1 Boost"},
2151 {"Right Rec Mixer", "Mic2 Capture Switch", "Mic2 Boost"},
2152 {"Right Rec Mixer", "HP Mixer Capture Switch", "Right HP Mixer"},
2153 {"Right Rec Mixer", "SPK Mixer Capture Switch", "SPK Mixer"},
2154 {"Right Rec Mixer", "MoNo Mixer Capture Switch", "Mono Mixer"},
2156 {"Left ADC", NULL, "DAC Ref"},
2157 {"Left ADC", NULL, "Left Rec Mixer"},
2158 {"Right ADC", NULL, "DAC Ref"},
2159 {"Right ADC", NULL, "Right Rec Mixer"},
2161 {"PCM src select Mux", "TxDP", "TxDP"},
2162 {"PCM src select Mux", "ADCR", "Right ADC"},
2165 {"ADC", NULL, "Left ADC"},
2166 {"ADC", NULL, "Right ADC"},
2167 {"IIS src select Mux", "ADC", "ADC"},
2168 //{"IIS src select Mux", "ADC", "Left ADC"},
2169 //{"IIS src select Mux", "ADC", "Right ADC"},
2171 {"IIS src select Mux", "Voice to Stereo", "AIF2RX"},
2172 {"IIS src select Mux", "SRC2 Output", "SRC2 Enable"},
2174 {"AIF2TX", NULL, "IIS Interface"},
2175 {"AIF2TX", NULL, "PCM src select Mux"},
2176 {"AIF1TX", NULL, "IIS Interface"},
2177 {"AIF1TX", NULL, "IIS src select Mux"},
2180 {"AIF1RX", NULL, "IIS Interface"},
2181 {"AIF2RX", NULL, "IIS Interface"},
2183 {"DAC fun Mux", "SRC2 Out", "SRC2 Enable"},
2184 {"DAC fun Mux", "TxDP", "TxDP"},
2185 {"DAC fun Mux", "TxDC", "TxDC"},
2186 {"DAC fun Mux", "Stereo DAC", "AIF1RX"},
2188 {"VDAC src Mux", "SRC2 Out", "SRC2 Enable"},
2189 {"VDAC src Mux", "TxDP", "TxDP"},
2190 {"VDAC src Mux", "TxDC", "TxDC"},
2191 {"VDAC src Mux", "Voice PCM", "AIF2RX"},
2193 {"Left DAC", NULL, "DAC Ref"},
2194 {"Left DAC", NULL, "DAC fun Mux"},
2195 {"Right DAC", NULL, "DAC Ref"},
2196 {"Right DAC", NULL, "DAC fun Mux"},
2197 {"Voice DAC", NULL, "DAC Ref"},
2198 {"Voice DAC", NULL, "VDAC src Mux"},
2200 {"Left LineIn Volume", NULL, "Left LineIn"},
2201 {"Right LineIn Volume", NULL, "Right LineIn"},
2202 {"Phone Volume", NULL, "Phone"},
2203 {"Mic1 Volume", NULL, "Mic1 Boost"},
2204 {"Mic2 Volume", NULL, "Mic2 Boost"},
2206 {"Left DAC To Mixer", NULL, "Left DAC"},
2207 {"Right DAC To Mixer", NULL, "Right DAC"},
2208 {"Voice DAC To Mixer", NULL, "Voice DAC"},
2210 {"DAC Mixer", NULL, "Left DAC To Mixer"},
2211 {"DAC Mixer", NULL, "Right DAC To Mixer"},
2212 {"Line Mixer", NULL, "Left LineIn Volume"},
2213 {"Line Mixer", NULL, "Right LineIn Volume"},
2215 {"Mono HP Mixer", "LineIn Playback Switch", "Line Mixer"},
2216 {"Mono HP Mixer", "Phone Playback Switch", "Phone Volume"},
2217 {"Mono HP Mixer", "Mic1 Playback Switch", "Mic1 Volume"},
2218 {"Mono HP Mixer", "Mic2 Playback Switch", "Mic2 Volume"},
2219 {"Mono HP Mixer", "Voice DAC Playback Switch", "Voice DAC To Mixer"},
2220 {"Left HP Mixer", "ADC Playback Switch", "Left Rec Mixer"},
2221 {"Left HP Mixer", "DAC Playback Switch", "Left DAC To Mixer"},
2222 {"Right HP Mixer", "ADC Playback Switch", "Right Rec Mixer"},
2223 {"Right HP Mixer", "DAC Playback Switch", "Right DAC To Mixer"},
2225 {"SPK Mixer", "Line Mixer Playback Switch", "Line Mixer"},
2226 {"SPK Mixer", "Phone Playback Switch", "Phone Volume"},
2227 {"SPK Mixer", "Mic1 Playback Switch", "Mic1 Volume"},
2228 {"SPK Mixer", "Mic2 Playback Switch", "Mic2 Volume"},
2229 {"SPK Mixer", "DAC Mixer Playback Switch", "DAC Mixer"},
2230 {"SPK Mixer", "Voice DAC Playback Switch", "Voice DAC To Mixer"},
2232 {"Mono Mixer", "Line Mixer Playback Switch", "Line Mixer"},
2233 {"Mono Mixer", "ADCL Playback Switch","Left Rec Mixer"},
2234 {"Mono Mixer", "ADCR Playback Switch","Right Rec Mixer"},
2235 {"Mono Mixer", "Mic1 Playback Switch", "Mic1 Volume"},
2236 {"Mono Mixer", "Mic2 Playback Switch", "Mic2 Volume"},
2237 {"Mono Mixer", "DAC Mixer Playback Switch", "DAC Mixer"},
2238 {"Mono Mixer", "Voice DAC Playback Switch", "Voice DAC To Mixer"},
2240 {"HP Mixer", NULL, "Mono HP Mixer"},
2241 {"HP Mixer", NULL, "Left HP Mixer"},
2242 {"HP Mixer", NULL, "Right HP Mixer"},
2244 {"SPK Vol Input Mux", "VMID", "VMID"},
2245 {"SPK Vol Input Mux", "HP Mixer", "HP Mixer"},
2246 {"SPK Vol Input Mux", "SPK Mixer", "SPK Mixer"},
2247 {"SPK Vol Input Mux", "Mono Mixer", "Mono Mixer"},
2248 {"SPK Vol Input Mux", NULL, "SPKL Vol"},
2249 {"SPK Vol Input Mux", NULL, "SPKR Vol"},
2251 {"HPL Vol Input Mux", "HP Mixer", "HP Mixer"},
2252 {"HPL Vol Input Mux", "VMID", "VMID"},
2253 {"HP Amp", NULL, "HPL Vol Input Mux"},
2254 {"HPR Vol Input Mux", "HP Mixer", "HP Mixer"},
2255 {"HPR Vol Input Mux", "VMID", "VMID"},
2256 {"HP Amp", NULL, "HPR Vol Input Mux"},
2258 {"AUX Vol Input Mux", "VMID", "VMID"},
2259 {"AUX Vol Input Mux", "HP Mixer", "HP Mixer"},
2260 {"AUX Vol Input Mux", "SPK Mixer", "SPK Mixer"},
2261 {"AUX Vol Input Mux", "Mono Mixer", "Mono Mixer"},
2263 {"SPKL", NULL, "SPK Amp"},
2264 {"SPKL", NULL, "SPK Vol Input Mux"},
2265 {"SPKR", NULL, "SPK Amp"},
2266 {"SPKR", NULL, "SPK Vol Input Mux"},
2267 {"HPL", NULL, "HP Amp"},
2268 {"HPR", NULL, "HP Amp"},
2269 {"AUX", NULL, "AUX Vol Input Mux"},
2272 {"SRC1 Enable", "Switch", "AIF1RX"},
2274 {"RxDP src select Mux", "Voice to Stereo", "AIF2RX"},
2275 {"RxDP src select Mux", "ADCL to VoDSP", "Left ADC"},
2276 {"RxDP src select Mux", "SRC1 Output", "SRC1 Enable"},
2277 {"RxDP src select Mux", "ADCR to VoDSP", "Right ADC"},
2279 {"RxDP Enable", "Switch", "RxDP src select Mux"},
2280 {"RxDC Enable", "Switch", "Left ADC"},
2282 {"RxDP", NULL, "RxDP Enable"},
2283 {"RxDC", NULL, "RxDC Enable"},
2284 {"PDM", NULL, "Right ADC"},
2286 {"Voice DSP", NULL, "RxDP"},
2287 {"Voice DSP", NULL, "RxDC"},
2288 {"Voice DSP", NULL, "PDM"},
2290 {"TxDP", NULL, "Voice DSP"},
2291 {"TxDC", NULL, "Voice DSP"},
2293 {"SRC2 src select Mux", "TxDP", "TxDP"},
2294 {"SRC2 src select Mux", "TxDC", "TxDC"},
2295 {"SRC2 Enable", "Switch", "SRC2 src select Mux"},
2304 /**************************************************************
2306 * our codec support you to select different source as pll input, but if you
2307 * use both of the I2S audio interface and pcm interface instantially.
2308 * The two DAI must have the same pll setting params, so you have to offer
2309 * the same pll input, and set our codec's sysclk the same one, we suggest
2311 **************************************************************/
2312 static const struct _pll_div codec_master_pll1_div[] = {
2313 { 2048000, 8192000, 0x0ea0},
2314 { 3686400, 8192000, 0x4e27},
2315 { 12000000, 8192000, 0x456b},
2316 { 13000000, 8192000, 0x495f},
2317 { 13100000, 8192000, 0x0320},
2318 { 2048000, 11289600, 0xf637},
2319 { 3686400, 11289600, 0x2f22},
2320 { 12000000, 11289600, 0x3e2f},
2321 { 13000000, 11289600, 0x4d5b},
2322 { 13100000, 11289600, 0x363b},
2323 { 2048000, 16384000, 0x1ea0},
2324 { 3686400, 16384000, 0x9e27},
2325 { 12000000, 16384000, 0x452b},
2326 { 13000000, 16384000, 0x542f},
2327 { 13100000, 16384000, 0x03a0},
2328 { 2048000, 16934400, 0xe625},
2329 { 3686400, 16934400, 0x9126},
2330 { 12000000, 16934400, 0x4d2c},
2331 { 13000000, 16934400, 0x742f},
2332 { 13100000, 16934400, 0x3c27},
2333 { 2048000, 22579200, 0x2aa0},
2334 { 3686400, 22579200, 0x2f20},
2335 { 12000000, 22579200, 0x7e2f},
2336 { 13000000, 22579200, 0x742f},
2337 { 13100000, 22579200, 0x3c27},
2338 { 2048000, 24576000, 0x2ea0},
2339 { 3686400, 24576000, 0xee27},
2340 { 11289600, 24576000, 0x950F},
2341 { 12000000, 24576000, 0x2915},
2342 { 12288000, 24576000, 0x0600},
2343 { 13000000, 24576000, 0x772e},
2344 { 13100000, 24576000, 0x0d20},
2345 { 26000000, 24576000, 0x2027},
2346 { 26000000, 22579200, 0x392f},
2347 { 24576000, 22579200, 0x0921},
2348 { 24576000, 24576000, 0x02a0},
2351 static const struct _pll_div codec_bclk_pll1_div[] = {
2352 { 256000, 4096000, 0x3ea0},
2353 { 352800, 5644800, 0x3ea0},
2354 { 512000, 8192000, 0x3ea0},
2355 { 705600, 11289600, 0x3ea0},
2356 { 1024000, 16384000, 0x3ea0},
2357 { 1411200, 22579200, 0x3ea0},
2358 { 1536000, 24576000, 0x3ea0},
2359 { 2048000, 16384000, 0x1ea0},
2360 { 2822400, 22579200, 0x1ea0},
2361 { 3072000, 24576000, 0x1ea0},
2362 { 705600, 11289600, 0x3ea0},
2363 { 705600, 8467200, 0x3ab0},
2364 { 2822400, 11289600, 0x1ee0},
2365 { 3072000, 12288000, 0x1ee0},
2368 static const struct _pll_div codec_vbclk_pll1_div[] = {
2369 { 256000, 4096000, 0x3ea0},
2370 { 352800, 5644800, 0x3ea0},
2371 { 512000, 8192000, 0x3ea0},
2372 { 705600, 11289600, 0x3ea0},
2373 { 1024000, 16384000, 0x3ea0},
2374 { 1411200, 22579200, 0x3ea0},
2375 { 1536000, 24576000, 0x3ea0},
2376 { 2048000, 16384000, 0x1ea0},
2377 { 2822400, 22579200, 0x1ea0},
2378 { 3072000, 24576000, 0x1ea0},
2379 { 705600, 11289600, 0x3ea0},
2380 { 705600, 8467200, 0x3ab0},
2383 struct _coeff_div_stereo {
2390 struct _coeff_div_voice {
2396 /* bclk is config to 32fs, if codec is choose to be slave mode,
2397 input bclk should be 32*fs */
2398 static const struct _coeff_div_stereo coeff_div_stereo[] = {
2399 {24576000, 48000, 0x3174, 0x1010},
2400 {12288000, 48000, 0x1174, 0x0000},
2401 {18432000, 48000, 0x2174, 0x1111},
2402 {36864000, 48000, 0x2274, 0x2020},
2403 {49152000, 48000, 0xf074, 0x3030},
2404 {24576000, 48000, 0x3172, 0x1010},
2405 {24576000, 8000, 0xB274, 0x2424},
2406 {24576000, 16000, 0xB174, 0x2222},
2407 {24576000, 32000, 0xB074, 0x2121},
2408 {22579200, 11025, 0X3374, 0x1414},
2409 {22579200, 22050, 0X3274, 0x1212},
2410 {22579200, 44100, 0X3174, 0x1010},
2411 {12288000, 8000, 0xB174, 0x2222},
2412 {11289600, 44100, 0X3072, 0x0000},
2415 /* bclk is config to 32fs, if codec is choose to be slave mode,
2416 input bclk should be 32*fs */
2417 static const struct _coeff_div_voice coeff_div_voice[] = {
2418 {24576000, 16000, 0x2622},
2419 {24576000, 8000, 0x2824},
2420 {2048000,8000,0x3000},
2423 static int get_coeff(unsigned int mclk, unsigned int rate, int mode)
2427 pr_info("mclk = %d, rate = %d, mode = %d\n", mclk, rate, mode);
2430 for (i = 0; i < ARRAY_SIZE(coeff_div_stereo); i++) {
2431 if ((coeff_div_stereo[i].rate == rate) &&
2432 (coeff_div_stereo[i].mclk == mclk))
2436 for (i = 0; i< ARRAY_SIZE(coeff_div_voice); i++) {
2437 if ((coeff_div_voice[i].rate == rate) &&
2438 (coeff_div_voice[i].mclk == mclk))
2442 pr_err("can't find a matched mclk and rate in %s\n",
2443 (mode ? "coeff_div_voice[]" : "coeff_div_audio[]"));
2449 static int rt5625_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source,
2450 unsigned int freq_in, unsigned int freq_out)
2452 struct snd_soc_codec *codec = dai->codec;
2453 int i, ret = -EINVAL;
2455 if (pll_id < RT5625_PLL_MCLK || pll_id > RT5625_PLL_VBCLK)
2458 if (!freq_in || !freq_out) {
2459 dev_info(dai->dev, "PLL is closed\n");
2460 snd_soc_update_bits(codec, RT5625_GEN_CTRL1,
2461 RT5625_SCLK_MASK, RT5625_SCLK_MCLK);
2465 if (RT5625_PLL_MCLK == pll_id) {
2466 for (i = 0; i < ARRAY_SIZE(codec_master_pll1_div); i ++)
2467 if ((freq_in == codec_master_pll1_div[i].pll_in) &&
2468 (freq_out == codec_master_pll1_div[i].pll_out)) {
2469 snd_soc_write(codec, RT5625_GEN_CTRL2,
2470 RT5625_PLL1_S_MCLK);
2471 snd_soc_write(codec, RT5625_PLL_CTRL,
2472 codec_master_pll1_div[i].regvalue);
2473 snd_soc_update_bits(codec, RT5625_GEN_CTRL1,
2474 RT5625_SCLK_MASK, RT5625_SCLK_PLL1);
2478 } else if (RT5625_PLL_MCLK_TO_VSYSCLK == pll_id) {
2479 for (i = 0; i < ARRAY_SIZE(codec_master_pll1_div); i ++)
2481 if ((freq_in == codec_master_pll1_div[i].pll_in) && (freq_out == codec_master_pll1_div[i].pll_out))
2483 snd_soc_write(codec, RT5625_GEN_CTRL2, 0x0000); /*PLL source from MCLK*/
2484 snd_soc_write(codec, RT5625_PLL_CTRL, codec_master_pll1_div[i].regvalue); /*set pll code*/
2485 snd_soc_update_bits(codec, RT5625_GEN_CTRL1, 0x0030, 0x0030); /* Voice SYSCLK source from FLL1 */
2489 }else if (RT5625_PLL_BCLK == pll_id) {
2490 for (i = 0; i < ARRAY_SIZE(codec_bclk_pll1_div); i ++)
2491 if ((freq_in == codec_bclk_pll1_div[i].pll_in) &&
2492 (freq_out == codec_bclk_pll1_div[i].pll_out)) {
2493 snd_soc_write(codec, RT5625_GEN_CTRL2,
2494 RT5625_PLL1_S_BCLK);
2495 snd_soc_write(codec, RT5625_PLL_CTRL,
2496 codec_bclk_pll1_div[i].regvalue);
2497 snd_soc_update_bits(codec, RT5625_GEN_CTRL1,
2498 RT5625_SCLK_MASK, RT5625_SCLK_PLL1);
2502 } else if (RT5625_PLL_VBCLK == pll_id) {
2503 for (i = 0; i < ARRAY_SIZE(codec_vbclk_pll1_div); i ++)
2504 if ((freq_in == codec_vbclk_pll1_div[i].pll_in) &&
2505 (freq_out == codec_vbclk_pll1_div[i].pll_out)) {
2506 snd_soc_write(codec, RT5625_GEN_CTRL2,
2507 RT5625_PLL1_S_VBCLK);
2508 snd_soc_write(codec, RT5625_PLL_CTRL,
2509 codec_vbclk_pll1_div[i].regvalue);
2510 snd_soc_update_bits(codec, RT5625_GEN_CTRL1,
2511 RT5625_SCLK_MASK, RT5625_SCLK_PLL1);
2521 static int rt5625_set_dai_sysclk(struct snd_soc_dai *dai,
2522 int clk_id, unsigned int freq, int dir)
2524 struct snd_soc_codec *codec = dai->codec;
2525 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
2526 unsigned int val = 0;
2530 if (freq == rt5625->stereo_sysclk)
2532 rt5625->stereo_sysclk = freq;
2536 if (freq == rt5625->voice_sysclk)
2538 rt5625->voice_sysclk = freq;
2546 case RT5625_SCLK_S_MCLK:
2549 case RT5625_SCLK_S_PLL:
2550 val |= RT5625_SCLK_PLL1;
2554 dev_err(codec->dev, "Invalid clock id (%d)\n", clk_id);
2557 snd_soc_update_bits(codec, RT5625_GEN_CTRL1,
2558 RT5625_SCLK_MASK, val);
2560 dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id);
2565 static int rt5625_hw_params(struct snd_pcm_substream *substream,
2566 struct snd_pcm_hw_params *params,
2567 struct snd_soc_dai *dai)
2569 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2570 struct snd_soc_codec *codec = rtd->codec;
2571 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
2572 unsigned int iface = 0, rate = params_rate(params), coeff;
2574 switch (params_format(params)) {
2575 case SNDRV_PCM_FORMAT_S16_LE:
2578 case SNDRV_PCM_FORMAT_S20_3LE:
2579 iface |= RT5625_I2S_DL_20;
2582 case SNDRV_PCM_FORMAT_S24_LE:
2583 iface |= RT5625_I2S_DL_24;
2586 case SNDRV_PCM_FORMAT_S8:
2587 iface |= RT5625_I2S_DL_8;
2596 coeff = get_coeff(rt5625->stereo_sysclk, rate, 0);
2598 dev_err(codec->dev, "Unsupported clock setting\n");
2601 snd_soc_write(codec, RT5625_DAC_CLK_CTRL1,
2602 coeff_div_stereo[coeff].reg60);
2603 snd_soc_write(codec, RT5625_DAC_CLK_CTRL2,
2604 coeff_div_stereo[coeff].reg62);
2605 snd_soc_update_bits(codec, RT5625_SDP_CTRL,
2606 RT5625_I2S_DL_MASK, iface);
2611 coeff = get_coeff(rt5625->voice_sysclk, rate, 1);
2613 dev_err(codec->dev, "Unsupported clock setting\n");
2616 snd_soc_write(codec, RT5625_VDAC_CLK_CTRL1,
2617 coeff_div_voice[coeff].reg64);
2618 iface |= 0x0100; //Voice SYSCLK source from FLL1
2619 snd_soc_update_bits(codec, RT5625_EXT_SDP_CTRL,
2620 RT5625_I2S_DL_MASK, iface);
2627 #ifdef RT5625_F_SMT_PHO
2628 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
2629 rt5625->app_bmp |= RT5625_PLY_MASK;
2631 rt5625->app_bmp |= RT5625_REC_MASK;
2637 static int rt5625_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2639 struct snd_soc_codec *codec = dai->codec;
2640 unsigned int iface = 0;
2643 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2644 case SND_SOC_DAIFMT_CBM_CFM:
2648 case SND_SOC_DAIFMT_CBS_CFS:
2656 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2657 case SND_SOC_DAIFMT_I2S:
2660 case SND_SOC_DAIFMT_LEFT_J:
2661 iface |= RT5625_I2S_DF_LEFT;
2664 case SND_SOC_DAIFMT_DSP_A:
2665 iface |= RT5625_I2S_DF_PCM_A;
2668 case SND_SOC_DAIFMT_DSP_B:
2669 iface |= RT5625_I2S_DF_PCM_B;
2676 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2677 case SND_SOC_DAIFMT_NB_NF:
2680 case SND_SOC_DAIFMT_IB_NF:
2681 iface |= RT5625_I2S_BP_INV;
2687 iface |= 0x8000; /*enable vopcm*/
2692 iface |= RT5625_I2S_M_SLV;
2693 snd_soc_update_bits(codec, RT5625_SDP_CTRL,
2694 RT5625_I2S_M_MASK | RT5625_I2S_BP_MASK |
2695 RT5625_I2S_DF_MASK, iface);
2700 iface |= RT5625_PCM_M_SLV;
2701 snd_soc_update_bits(codec, RT5625_EXT_SDP_CTRL,
2702 RT5625_PCM_M_MASK | RT5625_I2S_BP_MASK |
2703 RT5625_I2S_DF_MASK, iface);
2712 #ifdef RT5625_F_SMT_PHO
2713 static int rt5625_trigger(struct snd_pcm_substream *substream,
2714 int cmd, struct snd_soc_dai *dai)
2716 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2717 struct snd_soc_codec *codec = rtd->codec;
2718 struct rt5625_priv *rt5625 = snd_soc_codec_get_drvdata(codec);
2719 int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
2722 case SNDRV_PCM_TRIGGER_START:
2723 case SNDRV_PCM_TRIGGER_RESUME:
2724 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2726 rt5625->app_bmp |= RT5625_REC_MASK;
2728 rt5625->app_bmp |= RT5625_PLY_MASK;
2731 case SNDRV_PCM_TRIGGER_STOP:
2732 case SNDRV_PCM_TRIGGER_SUSPEND:
2733 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2735 rt5625->app_bmp &= ~RT5625_REC_MASK;
2737 rt5625->app_bmp &= ~RT5625_PLY_MASK;
2738 rt5625->app_bmp &= ~RT5625_VOIP_MASK;
2749 static int rt5625_set_bias_level(struct snd_soc_codec *codec,
2750 enum snd_soc_bias_level level)
2753 case SND_SOC_BIAS_ON:
2755 snd_soc_update_bits(codec, RT5625_HP_OUT_VOL,
2756 RT5625_L_MUTE | RT5625_R_MUTE, 0);
2757 snd_soc_update_bits(codec, RT5625_SPK_OUT_VOL,
2758 RT5625_L_MUTE | RT5625_R_MUTE, 0);
2762 case SND_SOC_BIAS_PREPARE:
2763 snd_soc_write(codec, RT5625_PD_CTRL, 0x0000);
2764 snd_soc_update_bits(codec, RT5625_PWR_ADD1,
2765 RT5625_P_MB1 | RT5625_P_MB2,
2766 RT5625_P_MB1 | RT5625_P_MB2);
2769 case SND_SOC_BIAS_STANDBY:
2771 snd_soc_update_bits(codec, RT5625_HP_OUT_VOL,
2772 RT5625_L_MUTE | RT5625_R_MUTE,
2773 RT5625_L_MUTE | RT5625_R_MUTE);
2774 snd_soc_update_bits(codec, RT5625_SPK_OUT_VOL,
2775 RT5625_L_MUTE | RT5625_R_MUTE,
2776 RT5625_L_MUTE | RT5625_R_MUTE);
2777 snd_soc_update_bits(codec, RT5625_PWR_ADD1,
2778 RT5625_P_MB1 | RT5625_P_MB2, 0);
2780 if (SND_SOC_BIAS_OFF == codec->dapm.bias_level) {
2781 snd_soc_write(codec, RT5625_PD_CTRL, 0);
2782 snd_soc_write(codec, RT5625_PWR_ADD1,
2783 RT5625_P_MAIN_BIAS);
2784 snd_soc_write(codec, RT5625_PWR_ADD2, RT5625_P_VREF);
2785 codec->cache_only = false;
2786 snd_soc_cache_sync(codec);
2790 case SND_SOC_BIAS_OFF:
2792 snd_soc_update_bits(codec, RT5625_HP_OUT_VOL,
2793 RT5625_L_MUTE | RT5625_R_MUTE,
2794 RT5625_L_MUTE | RT5625_R_MUTE);
2795 snd_soc_update_bits(codec, RT5625_SPK_OUT_VOL,
2796 RT5625_L_MUTE | RT5625_R_MUTE,
2797 RT5625_L_MUTE | RT5625_R_MUTE);
2799 snd_soc_write(codec, RT5625_PWR_ADD1, 0x0000);
2800 snd_soc_write(codec, RT5625_PWR_ADD2, 0x0000);
2801 snd_soc_write(codec, RT5625_PWR_ADD3, 0x0000);
2805 codec->dapm.bias_level = level;
2811 static int rt5625_proc_init(void);
2814 static int rt5625_probe(struct snd_soc_codec *codec)
2818 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C);
2820 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
2828 rt5625_reset(codec);
2829 snd_soc_write(codec, RT5625_PD_CTRL, 0);
2830 snd_soc_write(codec, RT5625_PWR_ADD1, RT5625_P_MAIN_BIAS);
2831 snd_soc_write(codec, RT5625_PWR_ADD2, RT5625_P_VREF);
2833 rt5625_reg_init(codec);
2835 codec->dapm.bias_level = SND_SOC_BIAS_STANDBY;
2836 rt5625_codec = codec;
2840 static int rt5625_remove(struct snd_soc_codec *codec)
2842 rt5625_set_bias_level(codec, SND_SOC_BIAS_OFF);
2847 static int rt5625_suspend(struct snd_soc_codec *codec)
2849 rt5625_set_bias_level(codec, SND_SOC_BIAS_OFF);
2853 static int rt5625_resume(struct snd_soc_codec *codec)
2855 rt5625_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
2859 #define rt5625_suspend NULL
2860 #define rt5625_resume NULL
2863 #define RT5625_STEREO_RATES SNDRV_PCM_RATE_8000_48000
2864 #define RT5625_VOICE_RATES SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_8000
2865 #define RT5625_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
2866 SNDRV_PCM_FMTBIT_S20_3LE |\
2867 SNDRV_PCM_FMTBIT_S24_LE |\
2868 SNDRV_PCM_FMTBIT_S8)
2870 struct snd_soc_dai_ops rt5625_aif_dai_ops = {
2871 #ifdef RT5625_F_SMT_PHO
2872 .trigger = rt5625_trigger,
2874 .hw_params = rt5625_hw_params,
2875 .set_fmt = rt5625_set_dai_fmt,
2876 .set_sysclk = rt5625_set_dai_sysclk,
2877 .set_pll = rt5625_set_dai_pll,
2880 struct snd_soc_dai_driver rt5625_dai[] = {
2882 .name = "rt5625-aif1",
2885 .stream_name = "HiFi Playback",
2888 .rates = RT5625_STEREO_RATES,
2889 .formats = RT5625_FORMATS,
2892 .stream_name = "HiFi Capture",
2895 .rates = RT5625_STEREO_RATES,
2896 .formats = RT5625_FORMATS,
2898 .ops = &rt5625_aif_dai_ops,
2901 .name = "rt5625-aif2",
2904 .stream_name = "Voice Playback",
2907 .rates = RT5625_VOICE_RATES,
2908 .formats = RT5625_FORMATS,
2911 .stream_name = "Voice Capture",
2914 .rates = RT5625_VOICE_RATES,
2915 .formats = RT5625_FORMATS,
2917 .ops = &rt5625_aif_dai_ops,
2921 static struct snd_soc_codec_driver soc_codec_dev_rt5625 = {
2922 .probe = rt5625_probe,
2923 .remove = rt5625_remove,
2924 .suspend = rt5625_suspend,
2925 .resume = rt5625_resume,
2926 .set_bias_level = rt5625_set_bias_level,
2927 .reg_cache_size = 0x80,
2928 .reg_word_size = sizeof(u16),
2929 .reg_cache_default = rt5625_reg,
2930 .volatile_register = rt5625_volatile_register,
2931 .readable_register = rt5625_readable_register,
2932 .reg_cache_step = 1,
2933 .controls = rt5625_snd_controls,
2934 .num_controls = ARRAY_SIZE(rt5625_snd_controls),
2935 .dapm_widgets = rt5625_dapm_widgets,
2936 .num_dapm_widgets = ARRAY_SIZE(rt5625_dapm_widgets),
2937 .dapm_routes = rt5625_dapm_routes,
2938 .num_dapm_routes = ARRAY_SIZE(rt5625_dapm_routes),
2941 static const struct i2c_device_id rt5625_i2c_id[] = {
2945 MODULE_DEVICE_TABLE(i2c, rt5625_i2c_id);
2951 compatible = "rt5625";
2953 spk-ctr-pin = <&gpio3 GPIO_D7 GPIO_ACTIVE_HIGH>;
2959 static int rt5625_parse_dt_property(struct device *dev,
2960 struct rt5625_priv *rt5625)
2962 struct device_node *node = dev->of_node;
2965 printk("%s()\n", __FUNCTION__);
2970 rt5625->spk_ctr_pin= of_get_named_gpio_flags(node, "spk-ctr-pin", 0, NULL);
2971 if (rt5625->spk_ctr_pin < 0) {
2972 DBG("%s() Can not read property spk-ctr-pin\n", __FUNCTION__);
2973 rt5625->spk_ctr_pin = INVALID_GPIO;
2976 ret = of_property_read_u32(node, "spk-ctr-on", &rt5625->spk_ctr_on);
2978 DBG("%s() Can not read property spk-ctr-on\n", __FUNCTION__);
2979 rt5625->spk_ctr_on = 1;
2982 ret = of_property_read_u32(node, "spk-ctr-off", &rt5625->spk_ctr_off);
2984 DBG("%s() Can not read property spk-ctr-off\n", __FUNCTION__);
2985 rt5625->spk_ctr_off = 0;
2991 static int rt5625_parse_dt_property(struct device *dev,
2992 struct rt3261_priv *rt3261)
2996 #endif //#ifdef CONFIG_OF
2998 static int rt5625_i2c_probe(struct i2c_client *i2c,
2999 const struct i2c_device_id *id)
3001 struct rt5625_priv *rt5625;
3003 //struct rt5625_platform_data *pdata = pdata = i2c->dev.platform_data;
3005 rt5625 = kzalloc(sizeof(struct rt5625_priv), GFP_KERNEL);
3009 ret = rt5625_parse_dt_property(&i2c->dev, rt5625);
3011 printk("%s() parse device tree property error %d\n", __FUNCTION__, ret);
3015 if(rt5625->spk_ctr_pin != INVALID_GPIO)
3017 gpio_request(rt5625->spk_ctr_pin,NULL);
3018 gpio_direction_output(rt5625->spk_ctr_pin,rt5625->spk_ctr_off);
3019 rt5625->spk_ctr_status = 0;
3022 i2c_set_clientdata(i2c, rt5625);
3024 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5625,
3025 rt5625_dai, ARRAY_SIZE(rt5625_dai));
3032 static int rt5625_i2c_remove(struct i2c_client *i2c)
3034 snd_soc_unregister_codec(&i2c->dev);
3035 kfree(i2c_get_clientdata(i2c));
3039 struct i2c_driver rt5625_i2c_driver = {
3042 .owner = THIS_MODULE,
3044 .probe = rt5625_i2c_probe,
3045 .remove = rt5625_i2c_remove,
3046 .id_table = rt5625_i2c_id,
3049 static int __init rt5625_modinit(void)
3051 return i2c_add_driver(&rt5625_i2c_driver);
3053 module_init(rt5625_modinit);
3055 static void __exit rt5625_modexit(void)
3057 i2c_del_driver(&rt5625_i2c_driver);
3059 module_exit(rt5625_modexit);
3061 MODULE_DESCRIPTION("ASoC RT5625 driver");
3062 MODULE_AUTHOR("Johnny Hsu <johnnyhsu@realtek.com>");
3063 MODULE_LICENSE("GPL");
3068 static ssize_t rt5625_proc_write(struct file *file, const char __user *buffer,
3069 unsigned long len, void *data)
3076 cookie_pot = (char *)vmalloc( len );
3083 if (copy_from_user( cookie_pot, buffer, len ))
3087 switch(cookie_pot[0])
3091 debug_write_read ++;
3092 debug_write_read %= 2;
3093 if(debug_write_read != 0)
3094 printk("Debug read and write reg on\n");
3096 printk("Debug read and write reg off\n");
3100 printk("Read reg debug\n");
3101 if(cookie_pot[1] ==':')
3103 debug_write_read = 1;
3104 strsep(&cookie_pot,":");
3105 while((p=strsep(&cookie_pot,",")))
3107 reg = simple_strtol(p,NULL,16);
3108 value = rt5625_read(rt5625_codec,reg);
3109 printk("rt5625_read:0x%04x = 0x%04x\n",reg,value);
3111 debug_write_read = 0;
3116 printk("Error Read reg debug.\n");
3117 printk("For example: echo r:22,23,24,25>rt5625_ts\n");
3122 printk("Write reg debug\n");
3123 if(cookie_pot[1] ==':')
3125 debug_write_read = 1;
3126 strsep(&cookie_pot,":");
3127 while((p=strsep(&cookie_pot,"=")))
3129 reg = simple_strtol(p,NULL,16);
3130 p=strsep(&cookie_pot,",");
3131 value = simple_strtol(p,NULL,16);
3132 rt5625_write(rt5625_codec,reg,value);
3133 printk("rt5625_write:0x%04x = 0x%04x\n",reg,value);
3135 debug_write_read = 0;
3140 printk("Error Write reg debug.\n");
3141 printk("For example: w:22=0,23=0,24=0,25=0>rt5625_ts\n");
3145 printk("Dump reg \n");
3147 for(reg = 0; reg < 0x6e; reg+=2)
3149 value = rt5625_read(rt5625_codec,reg);
3150 printk("rt5625_read:0x%04x = 0x%04x\n",reg,value);
3155 printk("Help for rt5625_ts .\n-->The Cmd list: \n");
3156 printk("-->'d&&D' Open or Off the debug\n");
3157 printk("-->'r&&R' Read reg debug,Example: echo 'r:22,23,24,25'>rt5625_ts\n");
3158 printk("-->'w&&W' Write reg debug,Example: echo 'w:22=0,23=0,24=0,25=0'>rt5625_ts\n");
3165 static const struct file_operations rt5625_proc_fops = {
3166 .owner = THIS_MODULE,
3169 static int rt5625_proc_init(void)
3171 struct proc_dir_entry *rt5625_proc_entry;
3172 rt5625_proc_entry = create_proc_entry("driver/rt5625_ts", 0777, NULL);
3173 if(rt5625_proc_entry != NULL)
3175 rt5625_proc_entry->write_proc = rt5625_proc_write;
3180 printk("create proc error !\n");